decompressing an compressed image
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Wayne King
2012-4-26
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 个评论
Jan
2012-4-26
@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
2012-4-26
@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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Continuous Wavelet Transforms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!