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);
ISAM__port__directory.rar_isam
版权申诉
73 浏览量
2022-09-23
18:05:47
上传
评论
收藏 1KB RAR 举报
刘良运
- 粉丝: 70
- 资源: 1万+