# convert picture pixels to matrix array- 2-D DCT in Java

Hi
I need to write Java Applet code  for 2-D DCT (Discrete cosine transform) something  like "dctdemo" in Matlab.

I need to have one original image (image for compressing ) , one result image (compresed  image). When i click button i want  to  displayed result image on the screen from original (compressed  with selected quality ex. from 1-100).

How can I convert picture pixels to matrix array,calculate them with  formula and draw array in to result picture??? or the procedure is different??

So please give me java applet code for this or code for converting pixels, also i need code for drawing pictures from matrix array.

Thank you

eda2155809a0e714e7c8d327e6e108df.png
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Have a look at http://people.csail.mit.edu/koen/PVEM.java and the code beginning with the comment:

0
Author Commented:
Thank you CEHJ. but i need pixels in matrix( [][] ) not in single array. Do you see formula X(k1,k2)???
0
Commented:
>>i need pixels in matrix( [][] ) not in single array.

That's not a problem - just divide it up into matrix[image.height][image.width]

>>Do you see formula X(k1,k2)???

Yes
0
Author Commented:
Hi CHEJ

Matrix must luck like in this image

[image.height][image.width] are constant values

Examp. i want to see pixel in 2-nd row and 3-col : mat[2,3] and change it with my formula, and save in to the new matrix array. and on the end draw the new array on new picture!!!

Now i think that you understand  me.

Sorry for my english

images.jpg
0
Commented:
In that case, unpack it into

int[][] matrix = new int[8][8];

That would of course mean that your image has 64 pixels - is that the case?
0
Author Commented:
CHEJ

function getPixels fill one dimensional array, i'm locking for matrix. in your example rgbArray  is one dimensional array!!!
[1 2 3 4 5 62 12 1 4 56] not like this!!!!

Thanks
0
Author Commented:
I need something that luck like this:

for i=0 to height do
for j=0 to with do
matrih[i,j]= pic.getPihelFromPicture(i,j)
}
}
This is pseudo  code
But function getPihelFromPicture is important???
0
Author Commented:
Or how can I convert 1d array to 2d array(matrix)???
0
Commented:
for (int i = 0; i < height;i++) {
for(int j = 0; j < width;j++)
matrix[i,j]= oneDArray[i * width + j];
}
}
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
CEHJ thank you for this,
Can you tell me how can I display image from PC in to the BufferedImage ??
0
Commented:
You can add the image to a label

0
Author Commented:
CEHJ:can you give me code for assign image from PC to bufferedimage!!!
How can i tell to the bufferedimage, witch image on PC do I put in bufferedimage!!for geting pixels

I am new in java!!

Thank you !!
0
Commented:
0
Commented:
:-)
0
Author Commented:
;)
CEHJ if you can please tell me who are library (imports) for this:

Thak you!
0
Commented:
0
Author Commented:
InputStream in =
getClass().getResourceAsStream("image.jpg");