softness.m

来自「此程序为本人编写的关于数字图像处理方面的matlab程序」· M 代码 · 共 71 行

M
71
字号
clc
clear
close all
a0=imread('D:\Mary.bmp');
subplot(221);
imshow(a0);
title('原图像');
a= imnoise(a0,'salt & pepper',0.02);
a0=double(a0);
b=zeros(1,256);
c=[b;a0;b];
%给图像矩阵数据的最左和最右加入两列0
d=zeros(258,1);
e=[d c d];
%建立一个3×3的平滑滤波器(模板),即3行3列的1的矩阵
panel=[1 1 1;1 1 1;1 1 1];
%进行模板运算
for i=2:257
    for j=2:257
        %取出图像中的3×3的矩阵
        image33=[e(i-1,j-1) e(i-1,j) e(i-1,j+1);
                 e(i,j-1)   e(i,j)   e(i,j+1);
                 e(i+1,j-1) e(i+1,j) e(i+1,j+1)];
             temp=0;
             for m=1:3
                 for n=1:3  
                  temp= image33(m,n)*panel(m,n)+temp;
                 end
             end
             panelimage(i,j)=temp/9;
             
    end
end
panelimage=mat2gray(panelimage);
subplot(222);
imshow(panelimage);
title('原图像平滑滤波');
subplot(223)
imshow(a);
a=double(a);
title('加噪音后的图像');
a=double(a);
%给图像矩阵数据的最上和最下加入两行0
b=zeros(1,256);
c=[b;a;b];
%给图像矩阵数据的最左和最右加入两列0
d=zeros(258,1);
e=[d c d];
%建立一个3×3的平滑滤波器(模板),即3行3列的1的矩阵
panel=[1 1 1;1 1 1;1 1 1];
%进行模板运算
for i=2:257
    for j=2:257
        %取出图像中的3×3的矩阵
        image33=[e(i-1,j-1) e(i-1,j) e(i-1,j+1);
                 e(i,j-1)   e(i,j)   e(i,j+1);
                 e(i+1,j-1) e(i+1,j) e(i+1,j+1)];
             temp=0;
             for m=1:3
                 for n=1:3  
                  temp= image33(m,n)*panel(m,n)+temp;
                 end
             end
             panelimage(i,j)=temp/9;
             
    end
end
panelimage=mat2gray(panelimage);
subplot(224);
imshow(panelimage);
title('加噪音后平滑滤波');

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?