Solved

how to get pixel from an image in multidimensional array

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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.

756 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