my DCT2 algorithm results in blank image, please help

2 views (last 30 days)
liam xu
liam xu on 23 May 2022
Commented: liam xu on 23 May 2022
have a grey image lenna512.bmp as im, were asked to do the two-dimensional DCT of all the 8 X 8 non-overlapping blocks of the image im, and merge the left-top pixel of all blocks after the DCT transformation to get a smaller image ims.
this is what I did:
A = double(imread('lenna512.bmp'));
B = zeros(64,64);
for i = 1:64
for j = 1:64
%Split the original image into non-overlapping 8*8blocks
%making a total of 64*64=4096
C = A((8*i-7):8*i, (8*j-7):8*j);
%Call the build-in function to perform a
%2-dimentional Fourier transform on each block
D = dct2(C);
%Fill the top left element of the
%completed block to a new matrix
B(i,j) = D(1,1);
end
end
%imwrite(uint8(B),'ims.bmp');
imshow(uint8(B));
it shows a blank image without any details, please tell me how to fix it
  1 Comment
liam xu
liam xu on 23 May 2022
sorry it's not the fourier transform it's a cosine transform

Sign in to comment.

Answers (1)

Chunru
Chunru on 23 May 2022
A = rgb2gray(imread('Lenna.png'));
figure; imshow(A);
whos
Name Size Bytes Class Attributes A 512x512 262144 uint8 I 512x512x3 786432 uint8 cmdout 1x33 66 char
B = zeros(64,64);
for i = 1:64
for j = 1:64
%Split the original image into non-overlapping 8*8blocks
%making a total of 64*64=4096
C = A((8*i-7):8*i, (8*j-7):8*j);
%Call the build-in function to perform a
%2-dimentional Fourier transform on each block
D = dct2(double(C));
%Fill the top left element of the
%completed block to a new matrix
B(i,j) = D(1,1);
end
end
%imwrite(uint8(B),'ims.bmp');
%imshow(uint8(B));
figure; imagesc(B)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!