my DCT2 algorithm results in blank image, please help
Show older comments
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
Answers (1)
A = rgb2gray(imread('Lenna.png'));
figure; imshow(A);
whos
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)
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!
