Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to get pixel from an image in multidimensional array

Posted on 2006-11-17
3
Medium Priority
?
366 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 520 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 video teaches viewers about errors in exception handling.
Suggested Courses

722 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