A
Alex
Hi,
I am a novice to image analysis, and trying to retrieve pixel values
using the PixelGrabber class. When I print the int array pixel values
obtained as below, I get this :
-10592163 -9144717 -5855067
-15921396 -15658224 -13750227
-16579326 -16776960 -15789810
-16776960 -16710912 -13881813
-14934501 -13158090 -8026236
That is, the number of pixels is correct and the magnitude of each
pixel value scales with the darkness of a pixel it represents... but,
they are negative and don't look like the values you'd exepct for a
256-bit, black and white, jpeg image. In case this helps, when I print
the ColorModel, I get this:
DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=ff000000
but I don't know what these symbols mean.
I've already tried to save getPixels() output into a byte[] array
instead of int[], then convert into int[]. Also, I used Byte class and
its intValue() to do the same. No success either.
Can anyone suggest what I am doing wrong? Thanks in advance!
Here's the code:
/***********************************************/
// This class extends PixelGrabber, which is what "super" refers to
AM_PixelGrabber(Image img) //Constructor
{
super(img, 0, 0, -1, -1, true);
{
public void extractPixels() // the method to extract pixels
{
try
{
if (grabPixels())
pixelsArr = (int[])getPixels(); // save pixels into a 1D int
array
}
catch(InterruptedException e) {}
System.out.println(getColorModel());
}
/***********************************************/
//The main method does this:
File f = new File("bw-15.jpg"); // Open the image file.
BufferedImage bufi = ImageIO.read(f); // Store image in buffer.
AM_PixelGrabber apg = new AM_PixelGrabber(bufi); // Constructor call
apg.extractPixels(); // Extract the pixels and store them in an array
// Then, I print the int array.
I am a novice to image analysis, and trying to retrieve pixel values
using the PixelGrabber class. When I print the int array pixel values
obtained as below, I get this :
-10592163 -9144717 -5855067
-15921396 -15658224 -13750227
-16579326 -16776960 -15789810
-16776960 -16710912 -13881813
-14934501 -13158090 -8026236
That is, the number of pixels is correct and the magnitude of each
pixel value scales with the darkness of a pixel it represents... but,
they are negative and don't look like the values you'd exepct for a
256-bit, black and white, jpeg image. In case this helps, when I print
the ColorModel, I get this:
DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=ff000000
but I don't know what these symbols mean.
I've already tried to save getPixels() output into a byte[] array
instead of int[], then convert into int[]. Also, I used Byte class and
its intValue() to do the same. No success either.
Can anyone suggest what I am doing wrong? Thanks in advance!
Here's the code:
/***********************************************/
// This class extends PixelGrabber, which is what "super" refers to
AM_PixelGrabber(Image img) //Constructor
{
super(img, 0, 0, -1, -1, true);
{
public void extractPixels() // the method to extract pixels
{
try
{
if (grabPixels())
pixelsArr = (int[])getPixels(); // save pixels into a 1D int
array
}
catch(InterruptedException e) {}
System.out.println(getColorModel());
}
/***********************************************/
//The main method does this:
File f = new File("bw-15.jpg"); // Open the image file.
BufferedImage bufi = ImageIO.read(f); // Store image in buffer.
AM_PixelGrabber apg = new AM_PixelGrabber(bufi); // Constructor call
apg.extractPixels(); // Extract the pixels and store them in an array
// Then, I print the int array.