my DCT2 algorithm results in blank image, please help

조회 수: 7 (최근 30일)
liam xu
liam xu 2022년 5월 23일
댓글: liam xu 2022년 5월 23일
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
liam xu
liam xu 2022년 5월 23일
sorry it's not the fourier transform it's a cosine transform

댓글을 달려면 로그인하십시오.

답변 (1개)

Chunru
Chunru 2022년 5월 23일
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)

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by