12.07.2015 Views

Digital Image Processing (using Java)

Digital Image Processing (using Java)

Digital Image Processing (using Java)

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

public static int clamp(float value) {}return Math.min(Math.max(Math.round(value), 0), 255);ROI (region of interest)<strong>Java</strong> MeanROI matthead.pngLISTING 5.13 Example of <strong>using</strong> a ROI in the calculation of mean grey level.public double meanValue(Buffered<strong>Image</strong> img) {Raster raster = img.getRaster();double sum = 0.0;for (int y = 0; y < img.getHeight(); ++y)for (int x = 0; x < img.getWidth(); ++x)sum += raster.getSample(x, y, 0);return sum / (img.getWidth()*img.getHeight());}public double meanValue(Buffered<strong>Image</strong> img, Rectangle region) {return meanValue(img.getSubimage(region.x, region.y,region.width, region.height));}(p.97)LISTING 5.14 <strong>Java</strong> code to enlarge an image by pixel replication.public static Buffered<strong>Image</strong> enlarge (Buffered<strong>Image</strong> image, int n ){int w = n*image.getWidth();int h = n*image.getHeight();Buffered<strong>Image</strong> enlarged<strong>Image</strong> = new Buffered<strong>Image</strong>(w, h, image.getType());for (int y = 0; y < h; ++y)for (int x=0; x < w; ++x)enlarged<strong>Image</strong>.setRGB(x, y, image.getRGB(x/n, y/n));}return enlarged<strong>Image</strong>;LISTING 5.15 <strong>Java</strong> code to shrink an image by skipping pixels.- 17 -

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!