Pixel values returned with getPixels() are wrong format

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.
 
T

Thomas Weidenfeller

Alex said:
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 :

Do not multipost (and don't crosspost either). You question has been
answered in another group. Now go hunting for the answer.

You might want to make yourself familiar with the basics of using
newsgroups.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top