⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rh.m

📁 此程序为本人编写的关于数字图像处理方面的matlab程序
💻 M
字号:
clc
clear
close all
a=imread('D:\Mary.bmp');
subplot(221);
imshow(a);
title('原图像');
a=double(a);
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 9 -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('3*3锐化滤波图像');
b=zeros(1,256);
c5=[b;b;a;b;b];
d=zeros(260,1);
e5=[d d c5 d d];
%取出5*5模版
panel55=[-1 -1 -1 -1 -1;-1 -1 -1 -1 -1;-1 -1 25 -1 -1;-1 -1 -1 -1 -1;-1 -1 -1 -1 -1];
%进行模板运算
for i=3:258
    for j=3:258
        %取出图像中的5*5的矩阵
        image55=[e5(i-2,j-2) e5(i-2,j-1) e5(i-2,j) e5(i-2,j+1) e5(i-2,j+2);
                 e5(i-1,j-2) e5(i-1,j-1) e5(i-1,j) e5(i-1,j+1) e5(i-1,j+2);
                 e5(i,j-2)   e5(i,j-1)   e5(i,j)   e5(i,j+1)   e5(i,j+2);
                 e5(i+1,j-2) e5(i+1,j-1) e5(i+1,j) e5(i+1,j+1) e5(i+1,j+2);
                 e5(i+2,j-2) e5(i+2,j-1) e5(i+2,j) e5(i+2,j+1) e5(i+2,j+2)];
             temp55=0;
             for m=1:5
                 for n=1:5  
                  temp55= image55(m,n)*panel55(m,n)+temp55;
                 end
             end
             panelimage55(i,j)=temp55/25;
             
    end
end
panelimage=mat2gray(panelimage);
subplot(223);
imshow(panelimage);
title('5*5锐化滤波图像');
%给图像矩阵数据的最上和最下加入两行0
b=zeros(1,256);
c=[b;b;b;a;b;b;b];
%给图像矩阵数据的最左和最右加入两列0
d=zeros(262,1);
e=[d d d c d d d];
%建立一个3×3的平滑滤波器(模板),即3行3列的1的矩阵
panel=[-1 -1 -1 -1 -1 -1 -1;-1 -1 -1 -1 -1 -1 -1;-1 -1 -1 -1 -1 -1 -1;-1 -1 -1 49 -1 -1 -1;...
        -1 -1 -1 -1 -1 -1 -1;-1 -1 -1 -1 -1 -1 -1;-1 -1 -1 -1 -1 -1 -1];
%进行模板运算
for i=4:259
    for j=4:259
        %取出图像中的3×3的矩阵
        image77=[e(i-3,j-3) e(i-2,j-3) e(i-1,j-3) e(i,j-3) e(i+1,j-3) e(i+2,j-3) e(i+3,j-3);
                e(i-3,j-2) e(i-2,j-2) e(i-1,j-2) e(i,j-2) e(i+1,j-2) e(i+2,j-2) e(i+3,j-2);
                e(i-3,j-1) e(i-2,j-1) e(i-1,j-1) e(i,j-1) e(i+1,j-1) e(i+2,j-1) e(i+3,j-1);
                e(i-3,j) e(i-2,j) e(i-1,j) e(i,j) e(i+1,j) e(i+2,j) e(i+3,j);
                e(i-3,j+1) e(i-2,j+1) e(i-1,j+1) e(i,j+1) e(i+1,j+1) e(i+2,j+1) e(i+3,j+1);
                e(i-3,j+2) e(i-2,j+2) e(i-1,j+2) e(i,j+2) e(i+1,j+2) e(i+2,j+2) e(i+3,j+2);
                e(i-3,j+3) e(i-2,j+3) e(i-1,j+3) e(i,j+3) e(i+1,j+3) e(i+2,j+3) e(i+3,j+3)];
            image77=(image77)';
             temp=0;
             for m=1:7
                 for n=1:7  
                  temp= image77(m,n)*panel(m,n)+temp;
                 end
             end
             panelimage(i,j)=temp/49;
             
    end
end
panelimage=mat2gray(panelimage);
subplot(224);
imshow(panelimage);
title('7*7锐化滤波图像');

⌨️ 快捷键说明

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