Read an image into the workspace, then convert the image to grayscale.
RGB = imread('autumn.tif');
I = im2gray(RGB);
Perform a 2-D DCT of the grayscale image using the dct2 function.
J = dct2(I);
Display the transformed image using a logarithmic scale. Notice that most of the energy is in the upper left corner.
imshow(log(abs(J)),[])
colormap parula
colorbar
Set values less than magnitude 10 in the DCT matrix to zero.
J(abs(J) < 10) = 0;
Reconstruct the image using the inverse DCT function idct2. Rescale the values to the range [0, 1] expected of images of data type double.
K = idct2(J);
K = rescale(K);
Display the original grayscale image alongside the processed image. The processed image has fewer high frequency details, such as in the texture of the trees.
montage({I,K})
title('Original Grayscale Image (Left) and Processed Image (Right)');