my DCT2 algorithm results in blank image, please help

7 visualizzazioni (ultimi 30 giorni)
liam xu
liam xu il 23 Mag 2022
Commentato: liam xu il 23 Mag 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

Risposte (1)

Chunru
Chunru il 23 Mag 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)

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by