实现程序段如下:
function uipanel4_SelectionChangeFcn(hObject, eventdata, handles) % hObject handle to uipanel4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global T
str=get(hObject,'string'); axes(handles.axes2); switch str
case '椒盐噪声' T=getimage;
prompt={'数日椒盐噪声参数1:'}; defans={'0.02'};
p=inputdlg(prompt,'input',1,defans); p1=str2num(p{1});
f=imnoise(handles.img,'salt & pepper',p1); imshow(f); handles.img=f;
guidata(hObject,handles); case '?高斯噪声' T=getimage;
prompt={'输入高斯噪声1:','输入高斯噪声2'}; defans={'0','0.02'};
21 / 52
p=inputdlg(prompt,'input',1,defans); p1=str2num(p{1}); p2=str2num(p{2});
f=imnoise(handles.img,'gaussian',p1,p2); imshow(f); handles.img=f;
guidata(hObject,handles); case '乘性噪声' T=getimage;
prompt={'输入乘性噪声1:'}; defans={'0.02'};
p=inputdlg(prompt,'input',1,defans); p1=str2num(p{1});
f=imnoise(handles.img,'speckle',p1); imshow(f); handles.img=f;
guidata(hObject,handles); end
(2)滤除噪声(椒盐噪声)。 滤波前
中值滤波后
22 / 52
线性滤波后
自适应滤波后
实现程序段如下:
function uipanel5_SelectionChangeFcn(hObject, eventdata, handles) %图像滤波
% hObject handle to uipanel5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global T
str=get(hObject,'string'); axes(handles.axes2);
23 / 52
switch str
case '中值滤波' T=getimage;
k=medfilt2(handles.img); imshow(k); handles.img=k;
guidata(hObject,handles); case '线性滤波' T=getimage;
h=[1 1 1;1 1 1;1 1 1]; H=h/9;
i=double(handles.img); k=convn(i,h); imshow(k,[]); handles.img=k;
guidata(hObject,handles); case '自适应滤波' T=getimage;
k=wiener2(handles.img,[5,5]); imshow(k); handles.img=k;
guidata(hObject,handles); end
低通滤波器滤波后
24 / 52