资源简介
结合【中值滤波,均值滤波,高斯滤波】和【laplacian算子,sobel算子。prewitt算子】对图片进行去噪和边缘增强处理。通过视觉对比和MSE/SNR/PSNR数值对比,得到9种组合的处理效果。
代码片段和文件信息
clc
clear all
close all
img = imread(‘testPic.tif‘);
img=img(1:128*161:128*16);
imwrite(img‘Source0.tif‘)
%% 均值滤波部分
figure(1);
subplot(345)
subimage(img);
title(‘原始图像‘);
Byave = filter2(fspecial(‘average‘3)img)/255; %进行3*3均值滤波
%空域锐化
p1 =fspecial(‘sobel‘);
subplot(342)
add1 =imfilter(Byavep1);
out1=add1+Byave;
subimage(out1);
title(‘sobel锐化结果(均值滤波)‘);
[SNRMSEPSNR]=getSNR(imgout1);
fprintf(‘均值滤波+sobel算子锐化:\nSNR:%f\nMSE:%f\nPSNR:%f\n‘SNRMSEPSNR)
subplot(343)
p2 =fspecial(‘prewitt‘);
add2 =imfilter(Byavep2);
out2=add2+Byave;
subimage(out2);
title(‘prewitt锐化结果(均值滤波)‘);
[SNRMSEPSNR]=getSNR(imgout2);
fprintf(‘均值滤波+prewitt算子锐化:\nSNR:%f\nMSE:%f\nPSNR:%f\n‘SNRMSEPSNR)
subplot(344)
p3 =fspecial(‘laplacian‘);
add3 =imfilter(Byavep3);
out3=add3+Byave;
imwrite(out3‘均值滤波+laplacian算子锐化.tif‘);
subimage(out3);
title(‘laplacian锐化结果(均值滤波))‘);
[SNRMSEPSNR]=getSNR(imgout2);
fprintf(‘均值滤波+laplacian算子锐化:\nSNR:%f\nMSE:%f\nPSNR:%f\n‘SNRMSEPSNR)
%% 中值滤波部分
Bymed=medfilt2(img[33]);
%空域锐化
p1 =fspecial(‘sobel‘);
subplot(346)
add1 =imfilter(Bymedp1);
out1=add1+Bymed;
subimage(out1);
title(‘sobel锐化结果(中值滤波)‘);
[SNRMSEPSNR]=getSNR(imgout1);
fprintf(‘中值滤波+sobel算子锐化:\nSNR:%f\nMSE:%f\nPSNR:%f\n‘SNRMSEPSNR)
subplot(347)
p2 =fspecial(‘prewitt‘);
add2 =imfilter(Bymedp2);
out2=add2+Bymed;
subimage(out2);
title(‘prewitt锐化结果(中值滤波)‘);
[SNRMSEPSNR]=getSNR(imgout2);
fprintf(‘中值滤波+prewitt算子锐化:\nSNR:%f\nMSE:%f\nPSNR:%f\n‘SNRMSEPSNR)
subplot(348)
p3 =fspecial(‘laplacian‘);
add3 =imfilter(Bymedp3);
out3=add3+Bymed;
imwrite(out3‘中值滤波+laplacian算子锐化.tif‘);
subimage(out3);
title(‘laplacian锐化结果(中值滤波)‘);
[SNRMSEPSNR]=getSNR(imgout3);
fprintf(‘中值滤波+laplacian算子锐化:\nSNR:%f\nMSE:%f\nPSNR:%f\n‘SNRMSEPSNR)
%% 高斯滤波部分
W = fspecial(‘gaussian‘[33]1);
Bygaussian = imfilter(img W ‘replicate‘);
p1 =fspecial(‘sobel‘);
subplot(3410)
add1 =imfilter(Bygaussianp1);
out1=add1+Bygaussian;
subimage(out1);
title(‘sobel锐化结果(高斯滤波)‘);
[SNRMSEPSNR]=getSNR(imgout1);
fprintf(‘高斯滤波+sobel算子锐化:\nSNR:%f\nMSE:%f\nPSNR:%f\n‘SNRMSEPSNR)
subplot(3411)
p2 =fspecial(‘prewitt‘);
add2 =imfilter(Bygaussianp2);
out2=add2+Bygaussian;
subimage(out2);
title(‘prewitt锐化结果(高斯滤波)‘);
[SNRMSEPSNR]=getSNR(imgout2);
fprintf(‘高斯滤波+prewitt算子锐化:\nSNR:%f\nMSE:%f\nPSNR:%f\n‘SNRMSEPSNR)
subplot(3412)
p3 =fspecial(‘laplacian‘);
add3 =imfilter(Bygaussianp3);
out3=add3+Bygaussian;
imwrite(out3‘高斯滤波+laplacian算子锐化.tif‘);
subimage(out3);
title(‘laplacian锐化结果(高斯滤波)‘);
[SNRMSEPSNR]=getSNR(imgout3);
fprintf(‘高斯滤波+laplacian算子锐化:\nSNR:%f\nMSE:%f\nPSNR:%f\n‘SNRMSEPSNR)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2897 2020-11-07 21:56 图像锐化\bounderenhence.m
文件 302 2020-11-07 20:41 图像锐化\getSNR.m
文件 37748946 2020-11-07 18:50 图像锐化\testPic.tif
评论
共有 条评论