Solved

how to get pixel from an image in multidimensional array

Posted on 2006-11-17
3
360 Views
Last Modified: 2008-01-09
I'm using JAI package.
How to get the pixel from an image but in the form multidimensional array?
Cause i must read the pixel in 8x8 block.
I found method getPixels() but the result is single array.
Can someone help me to solve this problem? Pls, pls, pls...
Thank you
0
Comment
Question by:cemplukcute2003
3 Comments
 

Author Comment

by:cemplukcute2003
ID: 17965077
Ok, i'm trying using PixelAccessor class.
And from there i got a method getPixels which give me the result in UnpackedImageData type.
Here is my code :

RenderedImage img = JAI.create("fileload", "lena512.pgm");
Raster rasterPic = img.getData();
SampleModel sample = rasterPic.getSampleModel();
PixelAccessor pixAcc = new PixelAccessor(img);
UnpackedImageData pix = pixAcc.getPixels(rasterPic, rasterPic.getBounds(), DataBuffer.TYPE_INT, false);
int[][] tempPix = pix.getIntData();

But why the method getIntData() gives result 1 row only?
Doesn't it suppose to give the whole pixel in an image?
Is there someone who can help me to solve this?
Thank you
0
 
LVL 10

Expert Comment

by:ADSLMark
ID: 17966282
Well I took the liberty to look inside the source code of the JAI PixelAccessor.

The javadoc is very unclear but the double array is used for bands. I found that the pixel information is stored in a single array and then stored into a double array where the number of bands becomes the second array length. So all the pixels are stored in sequence, for 8x8 that would mean 64 integers, just make a double for loop to get 8 integers 8 times, shouldn't be so hard.

Mark
0
 
LVL 9

Accepted Solution

by:
owenli27 earned 130 total points
ID: 17967689
I think it is a problem in the existed JAI version. Maybe new version could fix it.  For a temp solution, you can add a couple of line to create a two-dimenstion array by yourself.
...
...
int[][] tempPix = pix.getIntData();

int index = 0;
int[][] myPix = new int[img.getHeight()][img.getWidth()];            
for(int i=0; i<myPix.length; i++)
    for(int j=0; j<myPix[i].length; j++)
       myPix[i][j] = tempPix[0][index++];
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
backtracking recursion  code 19 54
java 8 lambda expresssions exception handling 3 75
couple of eclipse 5 25
Configure a Bean in an XML file 4 12
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now