Solved

how to get pixel from an image in multidimensional array

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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
check java version using powershell 13 471
Better way to make a string with template variables in java 3 53
Problem to Alipay 10 95
Running JavaFX on the Raspberry Pi 27 290
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

738 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