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

📄 mysmooth.m

📁 该压缩包中的程序实现对图像的平滑和锐化
💻 M
字号:
function [psmoothed,method]=mysmooth(pin)
%通用的平滑滤波函数
[row col]=size(pin);   %原始图像的大小
%对图像进行零填充
pfilled=zeros(row+2,col+2);
pfilled(2:row+1,2:col+1)=pin;
%输入选用的平滑方法的代号
method=input('input a number to select filter method,1,2,or 3:\n');
%定义均值滤波法的模板
H=ones(3,3)/9;
%根据输入的参数对图像进行平滑
psmoothed=zeros(row,col);
for i=1:row
    for j=1:col
        if(method==1)
            array=[pfilled(i,j) pfilled(i,j+1) pfilled(i,j+2);pfilled(i+1,j) pfilled(i+1,j+1) pfilled(i+1,j+2);pfilled(i+2,j) pfilled(i+2,j+2) pfilled(i+2,j+2)];
            psmoothed(i,j)=sum(sum(H.*array));
        elseif(method==2)
            array=[pfilled(i,j) pfilled(i,j+1) pfilled(i,j+2) pfilled(i+1,j) pfilled(i+1,j+1) pfilled(i+1,j+2) pfilled(i+2,j) pfilled(i+2,j+2) pfilled(i+2,j+2)];
            psmoothed(i,j)=median(array);
        elseif(method==3)
            array=[pfilled(i,j) pfilled(i,j+1) pfilled(i,j+2) pfilled(i+1,j) pfilled(i+1,j+1) pfilled(i+1,j+2) pfilled(i+2,j) pfilled(i+2,j+2) pfilled(i+2,j+2)];
            psmoothed(i,j)=min(array);
        else
            disp('wrong number to select filter method');
            return;
        end
    end
end
psmoothed=uint8(psmoothed);

⌨️ 快捷键说明

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