how to convert 8x8 matrix into image?

i am doing project in dct...i hav taken an image converted it into 8x8 matrix...and compressed it using dct...now i want to convert the dct 8x8 matrix output back to image...pls help me in writing the code.

 Accepted Answer

Mohammad Abouali
Mohammad Abouali on 21 Jan 2015
Edited: Mohammad Abouali on 21 Jan 2015
do the inverse dct or idct().

12 Comments

I dnt want to reconstruct the original image to perform idct...i just want to get the compressed dct image from the matrix...i hav 8x8 matrix...i just need code to transform the matrix into image so that i can view the image..hope u understood my question..
I perfectly Understood what you were saying. After compression in order to reconstruct your image you still need to use inverse of dct.
So, if you perform idct on the original dct of the image, you get the original image back (kind of). if you perform the idct on the compressed/quantized version of the dct then you get the reconstruction of the compressed image and then you can check how much quality did you loose relative to the uncompressed one.
This is pretty much how JPEG works.
Again by doing idct i will get another matrix only...but how to get the image from matrix??
Did you read the document that I sent you? On page 6 and 7 it tell's you how the idct can be used in the decompression!
You mentioned: "... by doing idct i will get another matrix only ..." well, image is just a matrix of numbers.
I moved your question here:
Abhinaya Rajasekaran: "I got the point that image is matrix of numbers...but i hav to show the image as output..not the matrix....how to display the matrix as image in matlab??"
use imshow() command. that is the command used in matlab to display a matrix of numbers as an image.
Moved your response here:
Abhinaya Rajasekaran: "I tried it i am not getting the image...getting some black grey and white colours only"
Couple of things: first try this
imshow(compImage,[]);
where compImage is the one you get after reconstructing the compressed Image. If that didn't work, check carefully the range of your values in that image.
If none works, check if you are reconstructing the image properly or if you are doing too much compression.
I tried for the same compressed matrix wich was in the pdf wich u gav me...for the above command no image is being displayed...
Well, those are just a sample 8x8 tile of an image. That's only to for the example. Try this:
Original = ...
[154 123 123 123 123 123 123 136;
192 180 136 154 154 154 136 110;
254 198 154 154 180 154 123 123;
239 180 136 180 180 166 123 123;
180 154 136 167 166 149 136 136;
128 136 123 136 154 180 198 154;
123 105 110 149 136 136 180 166;
110 136 123 123 123 136 154 136];
Decompressed = ...
[149 134 119 116 121 126 127 128;
204 168 140 144 155 150 135 125;
253 195 155 166 183 165 131 111;
245 185 148 166 184 160 124 107;
188 149 132 155 172 159 141 136;
132 123 125 143 160 166 168 171;
109 119 126 128 139 158 168 166;
111 127 127 114 118 141 147 135];
% These would be very small too see
figure, imshow(Original,[]);
figure, imshow(Decompressed,[]);
% to make it larger so easier to see
figure, imshow(imresize(Original,50,'nearest'),[])
figure, imshow(imresize(Decompressed,50,'nearest'),[])
You should get this for Original:
and this for the decompressed:
and Yes, they just look like some gray dots and white dots. Not so interesting. But that's only to show an example.
Thanks for the above ans...how can i display colour images for eg. Lena images from its respective matrix??
you can use imshow again. If the image is single band it shows it as gray scale, if it is an RGB image then it will show it as color.
I really recommend that you have a look on MATLAB Primer. Many of these questions are answered there.
You can also set the 'InitialMagnification' parameter in imshow to something like 800 or 1600 to show it larger, instead of calling imresize.
Actually didn't know about that. That's very useful to know. Thank you.

Sign in to comment.

More Answers (2)

I got the point that image is matrix of numbers...but i hav to show the image as output..not the matrix....how to display the matrix as image in matlab??
I tried it i am not getting the image...getting some black grey and white colours only

1 Comment

Don't start a new answer. Continue on the comment.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!