利用Matlab的GUI设计图形用户界面,实现图像平滑功能。
主要程序:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename.pathname]=uigetfile({'*.jpg';'*.jpeg';'*.bmp';'*.tif'});
fpath =[filename.pathname];
a=imread(fpath);
axes(handles.axes1);
imshow(a),title('原图像')
global I
I= rgb2gray(a);
axes(handles.axes2);
imshow(I),title('灰度图像')
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a = get(handles.popupmenu1,'value');
global I
axes(handles.axes3);
switch a
case 1
J1=imnoise(I,'salt & pepper',0.02);%添加椒盐噪声
imshow(J1),title('添加椒盐噪声后的图像');
case 2
J2=imnoise(I,'gaussian',0.02); %添加高斯噪声
imshow(J2),title('添加高斯噪声后的图像');
end
% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
b = get(handles.popupmenu2,'value');
global I
switch b
case 1
J1=imnoise(I,'salt & pepper',0.02);%添加椒盐噪声
Z1= medfilt2(J1,[3,3]);%对添加椒盐噪声后图像进行中值滤波
axes(handles.axes4);
imshow(Z1),title('中值滤波');
K1=imfilter(J1,fspecial('average',3));%对添加椒盐噪声后图像进行均值处理
axes(handles.axes5);
imshow(K1),title('均值滤波');
case 2
J2=imnoise(I,'gaussian',0.02); %添加高斯噪声
Z2= medfilt2(J2,[3,3]);%对添加高斯噪声后图像进行中值滤波
axes(handles.axes4);
imshow(Z2),title('中值滤波');
K2= imfilter(J2,fspecial('average',3)); %对添加高斯噪声后图像进行均值处理
axes(handles.axes5);
imshow(K2),title('均值滤波');
end
Guide设计界面
选择图像
加入椒盐噪声并处理
加入高斯噪声并处理