?? mysmooth.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 + -