Img = imread('wgxy.jpg'); imshow(Img); disp('原始图像字节::'); whos('Img') I = rgb2gray(Img); imshow(I); disp('灰度图像字节:'); whos('I'); J = dct2(I); figure, imshow(log(abs(J))), colorbar; b=uint32(15/100*1080); J=J(1:b,1:b); disp('分块后反变换前字节:'); whos('J'); J(1080,1080)=0 K = idct2(J); disp('离散余弦变换后字节:'); whos('K'); figure, imshow(I), title('原图'); figure, imshow(J), title('二维离散余弦变换结果'); figure, imshow(K, [0,255]), title('还原图');加一段程序把峰值信噪比显示出来,换一种方式
时间: 2024-01-19 20:04:28 浏览: 46
浅谈cv2.imread()和keras.preprocessing中的image.load_img()区别
5星 · 资源好评率100%
Img = imread('wgxy.jpg');
imshow(Img);
disp('原始图像字节::');
whos('Img')
I = rgb2gray(Img);
imshow(I);
disp('灰度图像字节:');
whos('I')
J = dct2(I);
figure, imshow(log(abs(J))), colorbar;
b=uint32(15/100*1080);
J=J(1:b,1:b);
disp('分块后反变换前字节:');
whos('J');
J(1080,1080)=0
K = idct2(J);
disp('离散余弦变换后字节:');
whos('K')
figure, imshow(I), title('原图');
figure, imshow(J), title('二维离散余弦变换结果');
figure, imshow(K, [0,255]), title('还原图');
MSE = sum(sum((double(I)-double(K)).^2))/(size(I,1)*size(I,2));
MAXI = max(I(:));
PSNR = 10*log10(MAXI^2/MSE);
disp(['峰值信噪比为: ', num2str(PSNR)]);
阅读全文