How can I decompress a DCT compressed image?
Show older comments
Hi, I was wondering how could I be able to decompress the image I've compressed in dct. I understand the decompression steps of images, but I don't know how to implement it in matlab. Much information would be appreciated
if true
% code
end if true
% code
end if true
im = imread('lena.ppm');
figure, imshow(im);
%a = imresize(im, [256 400]);
I = rgb2gray(im);
F = dct2(I);
figure, imshow(F * 0.01);
ff = idct2(F);
figure, imshow(ff/255);
[r,c] = size(I); %take size of image and as rows and columns
DF = zeros(r,c); %create vectors which store intermediate values
DFF = DF;
IDF = DF;
IDFF = DF;
depth = 4;% decides how many bits to keep after dct
N = 8; %block size
for i = 1 : N : r %iterate through rows then columns and columns
for j = 1 : N : c
f = I(i:i+N-1, j:j+N-1); %take values and put into f
df = dct2(f);
DF(i:i+N-1,j:j+N-1) = df; %DCT of blocks
dff = idct2(df);
DFF(i:i+N-1, j:j+N-1)= dff; %inverse DCT of blocks
df(N:-1:depth+1,:) = 0;
df(:,N:-1:depth+1) = 0;
IDF(i:i+N-1,j:j+N-1) = df;%DCT of blocks with depth considered
dff = idct2(df);
IDFF(i:i+N-1,j:j+N-1) = dff; %inverse DCT of blocks with depth considered
end
end
figure, imshow(DF / 255);
figure, imshow(DFF);
A = DFF / 255;
figure, imshow(A);
imwrite(A,'abc1.jpeg');
B = IDFF / 255;
imwrite(B,'abc2.jpeg');
figure, imshow(B);
compression_ratio = numel(N)/numel(depth);
end
Answers (0)
Categories
Find more on Image Transforms 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!