decompressing an compressed image
Show older comments
I have a code for compression please telll how to decompress an image from that compressd image
y=imread('dock.jpg');
y=rgb2gray(y);y=double(y)
threshold=0.125
y=imresize(y,[256 256 ])
low=min(min(y)); high=max(max(y)); % NEEDED LATER FOR DISPLAYING
figure,
imagesc(y), colormap(gray), axis off
title('original image')
w=wavmat;
ty = w'*y*w; % THE WAVELET TRANSFORMATION
tty=ty; % A TRICK TO ELIMNATE THE OVERALL
tty(1,1)=0; % AVERAGE FROM CONSIDERATION WHEN
dead=max(max(abs(tty)))*threshold/100; % DECIDING JUST HOW TO THRESHOLD
clear tty;
dy=ty;
index=find(abs(dy)<=dead);
dy(index)=zeros(size(index)); % SETTING LOTS OF ELEMENTS TO ZERO
cy = full(w*sparse(dy)*w'); % THE INVERSE WAVELET TRANSFORMATION
density = nnz(dy); % ENTRIES USED OUT OF 256^2 = 65536
disp(['Wavelet transformed and doctored matrix uses '])
disp([ num2str(density) ' entries out of 256^2 = 65536,'])
disp(['thus is ' num2str(100*density/65536) '% dense, and we get a '])
disp(['compression ratio of ' num2str(65536/nnz(dy)) ' to 1']) % "COMPRESSION RATIO" = 65536/DENSITY
figure,
imagesc(cy,[low high]), colormap(gray), axis off
title('compressed image')
2 Comments
Jan
on 26 Apr 2012
It would be helpful for all readers, if you post the relevant code only.
shital shinde
on 26 Aug 2019
yes. I also need the implimentation of inverse DCT. Its very helpful.
Answers (1)
Wayne King
on 26 Apr 2012
I'm not sure what you mean here by decompress, but what you have implemented is lossy compression so you cannot "invert" your process to come up with the exact original image. In other words, you cannot take your cy and reproduce y such that the norm of their difference is zero.
When you execute:
dy(index)=zeros(size(index))
You have set the wavelet coefficients below a certain level to 0. You no longer know what the value of those coefficients was, so when you invert the wavelet transform, you cannot match your original image.
Now, you could use ty (the wavelet transform of y) and invert that, but that is not a compressed image.
4 Comments
Pat
on 26 Apr 2012
Walter Roberson
on 26 Apr 2012
There is no *possible* lossless compression algorithm which can average better than 1:1 (over a sufficiently large set of inputs.)
*If* you had a program that could _always_ do at least 1:2, then to get 1:4 you would just apply the algorithm twice. If you had an image that was 2 bytes (16 bits) and you applied the hypothetical algorithm 5 times, how would you store the resulting half bit?
To *consistently* get 1:2 or better, you would need to use a lossy compression algorithm.
Jan
on 26 Apr 2012
@Pat: It is not helpful if you ask the same questions repeatedly instead of replying to the questions for clarifications. See: http://www.mathworks.com/matlabcentral/answers/36383-compressing-a-image
and http://www.mathworks.com/matlabcentral/answers/32129-compression-and-decompresion
Jan
on 26 Apr 2012
@Walter: Human tend to prefer images with less than the full entropy. Therefore lossless compressions are possible, if the rounding error are neglected, for a large set of usual pictures. But if a "sufficiently large set" includes random and max-entropy pictures, any 1:1+e compression must be lossless, as you have explained.
Categories
Find more on Denoising and Compression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!