J
jimgardener
hello all,
i want to extract the value of each pixel from an image (color or
greyscale)as single values.I wrote a function as follows.Here i am
getting the green,blue,red components using methods of ColorModel and
then taking the average(sum of r,g,b divided by 3).I don't know if
this is the right way to do this.Can anyone tell me if there is an
alternate/better method ?
thanks
jim
public double[] getpixels(String imgfilename)throws Exception{
BufferedImage img =ImageIO.read(new File(imgfilename));
int ht=img.getHeight() ;
int wd=img.getWidth();
int[] pixels = new int[wd * ht];
PixelGrabber pg = new PixelGrabber(img, 0, 0, wd, ht, pixels, 0, wd);
double[] result =new double[wd*ht];
ColorModel cm = pg.getColorModel();
for (int i=0; i<result.length; i++){
result = cm.getBlue(pixels) + cm.getGreen(pixels) +
cm.getRed(pixels);
result /= 3.0;
}
return result;
}
i want to extract the value of each pixel from an image (color or
greyscale)as single values.I wrote a function as follows.Here i am
getting the green,blue,red components using methods of ColorModel and
then taking the average(sum of r,g,b divided by 3).I don't know if
this is the right way to do this.Can anyone tell me if there is an
alternate/better method ?
thanks
jim
public double[] getpixels(String imgfilename)throws Exception{
BufferedImage img =ImageIO.read(new File(imgfilename));
int ht=img.getHeight() ;
int wd=img.getWidth();
int[] pixels = new int[wd * ht];
PixelGrabber pg = new PixelGrabber(img, 0, 0, wd, ht, pixels, 0, wd);
double[] result =new double[wd*ht];
ColorModel cm = pg.getColorModel();
for (int i=0; i<result.length; i++){
result = cm.getBlue(pixels) + cm.getGreen(pixels) +
cm.getRed(pixels);
result /= 3.0;
}
return result;
}