RGB = imread('autumn.tif');% read image
I = rgb2gray(RGB);% converted to grayscale image
J = dct2(I);% discrete cosine transform
figure, imshow(log(abs(J)) ,[]),% display the coefficients of the discrete cosine transform
colormap(jet(64)),
colorbar
J(abs(J) <10) = 0;% set the coefficient to 0
K = idct2(J);% discrete cosine inverse Transform
figure,
subplot(121),imshow(I); subplot(122), imshow(K,[0 255])
I = imread('cameraman.tif');% read image
I = im2double(I);% Converted to double type
T = dctmtx(8);% transformation matrix
dct = @(x)T * x * T'; %DCT transformation formula
B = blkproc(I,[8 8],dct);% block DCT conversion
mask = [1 1 1 1 0 0 0 0
1 1 1 1 0 0 0 0 0
1 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0]; The small coefficient of %DCT transform is set to 0
B2 = blkproc(B,[8 8],@(x)mask.* x);% block selects the coefficient of DCT transform
invdct = @(x)T' * x * T; %DCT inverse transformation formula
I2 = blkproc(B2,[8 8],invdct);% block reconstruction
figure,
subplot(121), imshow(I), subplot(122 ), imshow(I2)
MATLAB image transformation three
Guess you like
Origin blog.csdn.net/m0_38127487/article/details/115185776
Recommended
Ranking