i want to know how to find the size of original image & compressed image..

I want to find the size of compressed and original images size after applying FFT or DCT or PCA.Kindly if anyone have idea about it please share it with me.Thanks in advance.
p=imread('picture.jpg');
a=imresize(p,[100,100]);
%DCT
Z(:,:,1)=dct2(a(:,:,1));
Z(:,:,2)=dct2(a(:,:,2));
Z(:,:,3)=dct2(a(:,:,3));
for i=1:100
for j=1:100
if((i+j)>60)
Z(i,j,1)=0;
Z(i,j,2)=0;
Z(i,j,3)=0;
end
end
end
K(:,:,1)=idct2(Z(:,:,1));
K(:,:,2)=idct2(Z(:,:,2));
K(:,:,3)=idct2(Z(:,:,3));
subplot(2,4,1);
%imshow(Z);
imshow(uint8(K));
title('70% compression');
How can we find the size of the '70%' compressed image i.e K ?

2 Commenti

p=imread('picture.jpg');
a=imresize(p,[100,100]);
%DCT
Z(:,:,1)=dct2(a(:,:,1));
Z(:,:,2)=dct2(a(:,:,2));
Z(:,:,3)=dct2(a(:,:,3));
for i=1:100
for j=1:100
if((i+j)>60)
Z(i,j,1)=0;
Z(i,j,2)=0;
Z(i,j,3)=0;
end
end
end
K(:,:,1)=idct2(Z(:,:,1));
K(:,:,2)=idct2(Z(:,:,2));
K(:,:,3)=idct2(Z(:,:,3));
subplot(2,4,1);
%imshow(Z);
imshow(uint8(K));
title('70% compression');
How can we find the size of the '70%' compressed image i.e K ?

Accedi per commentare.

 Risposta accettata

Look at the file size in your operating system. For example, use Windows Explorer. Or if you want to do it all in MATLAB, use imfinfo(), if you have the Image Processing Toolbox.

9 Commenti

Try this:
info = imfinfo('peppers.png')
bytes = info.Width * info.Height * info.BitDepth
compressionRatio = bytes / info.FileSize
message = sprintf('The size is %d rows by %d columns by %d color channels = %d bytes.\n',...
info.Width, info.Height, info.BitDepth/3, bytes);
message = sprintf('%sThe size on disk is %d bytes.\n', message, info.FileSize);
message = sprintf('%sSo the file is %.3f%%as big as it could be\n(compressed by a factor of %.3f)\n', ...
message, 100/compressionRatio, compressionRatio)
uiwait(helpdlg(message));
In command window:
info =
Filename: 'C:\Program Files\MATLAB\R2013a\toolbox\images\imdemos\peppers.png'
FileModDate: '16-Dec-2002 06:10:58'
FileSize: 287677
Format: 'png'
FormatVersion: []
Width: 512
Height: 384
BitDepth: 24
ColorType: 'truecolor'
FormatSignature: [137 80 78 71 13 10 26 10]
Colormap: []
Histogram: []
InterlaceType: 'none'
Transparency: 'none'
SimpleTransparencyData: []
BackgroundColor: []
RenderingIntent: []
Chromaticities: []
Gamma: []
XResolution: []
YResolution: []
ResolutionUnit: []
XOffset: []
YOffset: []
OffsetUnit: []
SignificantBits: []
ImageModTime: '16 Jul 2002 16:46:41 +0000'
Title: []
Author: []
Description: 'Zesty peppers'
Copyright: 'Copyright The MathWorks, Inc.'
CreationTime: []
Software: []
Disclaimer: []
Warning: []
Source: []
Comment: []
OtherText: []
bytes =
4718592
compressionRatio =
16.4023957424473
message =
The size is 512 rows by 384 columns by 8 color channels = 4718592 bytes.
The size on disk is 287677 bytes.
So the file is 6.097% as big as it could be
(compressed by a factor of 16.402)
Dear sir... it is not clear ..i want to find the size of original and compressed image size...please help me ....thanks in advance...........
I really don't understand what you don't understand. You ask " i want to find the size of original " This is what it gives you when it says " The size .... = 4718592 bytes. "
Then you say " .i want to find the size ...compressed image size ". This is what it gives you when it says " The size on disk is 287677 bytes. "
So as far as I can see it answers both of those questions exactly, plus gives you more (like rows, columns, compression ratio). So why do you think it didn't answer those questions?
dear sir you are absolutely right...but i want to find the size of the image that i have compressed by DCT in the above code....kindly make it easy for me.........bundle of thanks for comments...........
I seriously don't know how to answer this. I gave you code for figuring out in your program what the full, uncompressed size is, and I gave you code for finding the file size of your image that you "have compressed by DCT in the above code". To me, it seems exactly what you asked. It is easy for you, at least as easy as three lines of code can get :
info = imfinfo('peppers.png')
uncompressedBytes = info.Width * info.Height * info.BitDepth
compressedBytes = info.FileSize
I gave you the two sizes - uncompressed and compressed. Why does that not answer your question? Maybe someone else can help here and explain why it's not what he asked.
thanks for reply................ dear sir ,in the above dct code when i find the size of image i.e uncompressed by size(uncompressed image),and when i compressed the image by dct and take inverse of it and the fine the size by size(compressed image),both are the same.then how it is compressed that is why i am asking question .i am not concern with the size of saved and unsaved image size...you are telling me the size of save image and unsaved i.e which is in command window..... please help me this is a step in my final year project....and if you have a code for image/data compression using dct or fft or dft, please share it with me...i shall be very thankful to you............and bundle of thanks for comments...........now please help me..............thanks
I don't doubt that when you compress it and "take inverse of it" (which I assume means uncompress it) that the sizes are the same. Isn't that what is supposed to happen? Even if you jpeg an image to the lowest quality you can, when you uncompress it, it will have the same size because the number of rows, columns, color channels, and number of bits per pixel will be the same. Of course it will look a lot worse but the size upon a round-trip compress/decompress will be the same.
When you compress an image array, a variable, and end up with a new image array variable, you write that out to disk to save the image, and you might add a header which adds a little bit. The size on disk depends on how much of the size in memory you write out. If you write out the whole thing, then that is the compressed size (ignoring the size of the header). You can use the "who" command to find out how many bytes your new compressed image array variable takes up in memory.
Dear sir,in the above code i have compressed the image by taking the higher component to zero.and then take the inverse of that compressed image...then how you can say that images is not compressed.... please if you have code on compressing image using dct/fft/dft please share it with me....please...... simply i want compressed image using fft/dct/dft.I need code.... please help me...please....................
When you compress it, it's compressed. If you inverse/reverse/restore/undo the compression, you recover your original image and it won't be compressed anymore. Don't you agree? I don't have any compression demos using fft or dct available to give you.

Accedi per commentare.

Più risposte (2)

original file size = (width* height*bit depth)/8;
and you can get compressed file size from imfinfo('imagefile'); and rest parameters to like width , height and bitdepth

4 Commenti

Dear sir, i am a little bit confused about the compressed images size .In the above mention case the length and width are the same both of original and compressed image so how we calculate the compressed size?
use the command
imfinfo('Filename'),
the file size you see here is the compressed size
dear if your problem is solved then please accept the answer
dear bro... its not clear..kindly find the size of compressed images of the above.... please take a example of image and solve my problem i shall be very thankful to you.........best luck

Accedi per commentare.

Hello! I would like to add a note here:
Be careful and check that you haven't registered into your workspace a variable named "sum". In that case this error also appears. It happened to me while computing MSE and PSNR in a matrix substraction like follows:
mse = sum(sum((I-I64).^2))/(m*n)
PSNR = 10*log(max(I(:))/sqrt(mse))
OUT:
Subscript indices must either be real positive
integers or logicals.
Error in mse_psnr (line 11)
mse = sum(sum((I-I64).^2))/(m*n)
Thanks to all.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by