Solved

how to get pixel from an image in multidimensional array

Posted on 2006-11-17
3
359 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

757 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

21 Experts available now in Live!

Get 1:1 Help Now