【图像处理】基于matlab中值+均值+高斯滤波+laplacian+sobel+prewitt图像去噪边缘增强【含Matlab源码 025期】

287 阅读2分钟

一、简介

基于matlab中值+均值+高斯滤波+laplacian+sobel+prewitt图像去噪边缘增强

二、源代码

clc
clear all
close all
img = imread('testPic.tif');
img=img(1:128*16,1:128*16);
imwrite(img,'Source0.tif')
%% 均值滤波部分
figure(1);
subplot(3,4,5)
subimage(img);
title('原始图像');
Byave = filter2(fspecial('average',3),img)/255; %进行3*3均值滤波
%空域锐化
p1 =fspecial('sobel');
subplot(3,4,2)
add1 =imfilter(Byave,p1);
out1=add1+Byave;
subimage(out1);
title('sobel锐化结果(均值滤波)');
[SNR,MSE,PSNR]=getSNR(img,out1);
fprintf('均值滤波+sobel算子锐化:\nSNR:%f\nMSE:%f\nPSNR:%f\n',SNR,MSE,PSNR)
subplot(3,4,3)
p2 =fspecial('prewitt');
add2 =imfilter(Byave,p2);
out2=add2+Byave;
subimage(out2);
title('prewitt锐化结果(均值滤波)');
[SNR,MSE,PSNR]=getSNR(img,out2);
fprintf('均值滤波+prewitt算子锐化:\nSNR:%f\nMSE:%f\nPSNR:%f\n',SNR,MSE,PSNR)
subplot(3,4,4)
p3 =fspecial('laplacian');
add3 =imfilter(Byave,p3);
out3=add3+Byave;
imwrite(out3,'均值滤波+laplacian算子锐化.tif');
subimage(out3);
title('laplacian锐化结果(均值滤波))');
[SNR,MSE,PSNR]=getSNR(img,out2);
fprintf('均值滤波+laplacian算子锐化:\nSNR:%f\nMSE:%f\nPSNR:%f\n',SNR,MSE,PSNR)
%% 中值滤波部分
Bymed=medfilt2(img,[3,3]);
%空域锐化
p1 =fspecial('sobel');
subplot(3,4,6)
add1 =imfilter(Bymed,p1);
out1=add1+Bymed;
subimage(out1);
title('sobel锐化结果(中值滤波)');
[SNR,MSE,PSNR]=getSNR(img,out1);
fprintf('中值滤波+sobel算子锐化:\nSNR:%f\nMSE:%f\nPSNR:%f\n',SNR,MSE,PSNR)
subplot(3,4,7)
p2 =fspecial('prewitt');
add2 =imfilter(Bymed,p2);
out2=add2+Bymed;
subimage(out2);
title('prewitt锐化结果(中值滤波)');
[SNR,MSE,PSNR]=getSNR(img,out2);
fprintf('中值滤波+prewitt算子锐化:\nSNR:%f\nMSE:%f\nPSNR:%f\n',SNR,MSE,PSNR)
subplot(3,4,8)
p3 =fspecial('laplacian');
add3 =imfilter(Bymed,p3);
out3=add3+Bymed;
imwrite(out3,'中值滤波+laplacian算子锐化.tif');
subimage(out3);
title('laplacian锐化结果(中值滤波)');
[SNR,MSE,PSNR]=getSNR(img,out3);
fprintf('中值滤波+laplacian算子锐化:\nSNR:%f\nMSE:%f\nPSNR:%f\n',SNR,MSE,PSNR)
%% 高斯滤波部分
W = fspecial('gaussian',[3,3],1); 
Bygaussian = imfilter(img, W, 'replicate');
 p1 =fspecial('sobel');
subplot(3,4,10)
add1 =imfilter(Bygaussian,p1);
out1=add1+Bygaussian;
subimage(out1);

三、运行结果

在这里插入图片描述

四、备注

版本:2014a