学自“MATLAB GUI界面设计”微信公众号
https://mp.weixin.qq.com/s/iygmHVMevkKzo618Yy_d0Q
https://pan.baidu.com/s/1rED_fGW56pIQTytXaro3Fg
https://download.csdn.net/download/qasxc78563/11142985
piture_procession.fig文件
piture_procession.m文件
%GUI图形界面初始化
function varargout = piture_procession(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @piture_procession_OpeningFcn, ...
'gui_OutputFcn', @piture_procession_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% --- Executes just before piture_procession is made visible.
function piture_procession_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to piture_procession (see VARARGIN)
% Choose default command line output for piture_procession
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes piture_procession wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = piture_procession_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
%图像导入并显示
function pushbutton1_Callback(hObject, eventdata, handles)
global im %将im变量设置成全局变量,这样子其他控件的回调函数才能调用这里的im变量
[filename,filepath]=uigetfile({'*.bmp;*.jpg;*.png;*.jpeg;*.tif;*gif;*Image files'},'选择图像');%获取图像文件名和路径
if isequal(filename,0)||isequal(filepath,0)
return;
end
image =[filepath,filename];%合成路径+文件名
im=imread(image);%imread()函数根据image中的路径和文件名找到图片,并将其读取到im中
axes(handles.axes1);%在显示图像之前,需要指定图像要显示在哪个坐标轴
imshow(im);%在坐标axes1显示图像
%添加高斯噪声
function pushbutton2_Callback(hObject, eventdata, handles)
global im %需要声明im是全局变量,这样子im就和其他控件的im是一样的值,否则就是个新的变量
i = imnoise(im,'gaussian');%imnoise()函数用来给图像添加噪声,可指定噪声的类型,这里是添加高斯噪声
axes(handles.axes2)
imshow(i);
%添加椒盐噪声
function pushbutton3_Callback(hObject, eventdata, handles)
global im
i = imnoise(im,'salt & pepper');
axes(handles.axes2)
imshow(i);
%添加泊松噪声
function pushbutton4_Callback(hObject, eventdata, handles)
global im
i = imnoise(im,'poisson');
axes(handles.axes2)
imshow(i);
%用滑动条做图像增强
function slider6_Callback(hObject, eventdata, handles)
global im;
% 提示:get(hObject,'Value')返回滑块的位置
a=get(handles.slider6,'value');
x1=imadjust(im,[0.3 0.7],[0 1],a);
axes(handles.axes2);
imshow(x1);
%滑动条设置
function slider6_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
%灰度变化
function pushbutton5_Callback(hObject, eventdata, handles)
global im
axes(handles.axes2)
y=rgb2gray(im);
imshow(y);
%去噪
function pushbutton6_Callback(hObject, eventdata, handles)
global im;
y=rgb2gray(im);
p = imnoise(y,'salt & pepper',0.1); %加10%的椒盐
axes(handles.axes1);
imshow(p);
g=medfilt2(p);
axes(handles.axes2);
imshow(g);
%旋转
function pushbutton7_Callback(hObject, eventdata, handles)
global im
theta=30;
p=imrotate(im,theta);
axes(handles.axes2);
imshow(p);
%二值化
function pushbutton8_Callback(hObject, eventdata, handles)
global im
y=rgb2gray(im);
n=graythresh(y);
axes(handles.axes2);
% im2bw(x,n);
output=imbinarize(y,n);
imshow(output);
% 保存
function pushbutton9_Callback(hObject, eventdata, handles)
% global b;
new_f_handle=figure('visible','off');
new_axes=copyobj(handles.axes2,new_f_handle); set(new_axes,'units','default','position','default');
[filename,pathname,fileindex]=uiputfile({'*.jpg';'*.bmp';'*.png'},'save picture as');
if ~filename
return
else
file=strcat(pathname,filename);
switch fileindex
case 1
print(new_f_handle,'-djpeg',file);
case 2
print(new_f_handle,'-dbmp',file);
case 3
print(new_f_handle,'-dpng',file)
end
end
delete(new_f_handle);
% 退出
function pushbutton10_Callback(hObject, eventdata, handles)
clc
close all
close(gcf)
clear
% Canny
function radiobutton1_Callback(hObject, eventdata, handles)
global im;
x1=imadjust(im,[0.3 0.7],[0 1],0.5);
axes(handles.axes2)
imshow(x1);
% str1=get(hObject,'string');
axes(handles.axes2);
y=rgb2gray(im);
dx=double(y);
R=edge(dx,'canny');
imshow(R);
%Roberts
function radiobutton2_Callback(hObject, eventdata, handles)
global im;
% str=get(hObject,'string');
axes(handles.axes2);
y=rgb2gray(im);
dx=double(y);
R=edge(dx,'roberts');
imshow(R);
%Sobel
function radiobutton3_Callback(hObject, eventdata, handles)
global im;
% str1=get(hObject,'string');
axes(handles.axes2);
y=rgb2gray(im);
dx=double(y);
R=edge(dx,'sobel');
imshow(R);
%Orginal
function radiobutton4_Callback(hObject, eventdata, handles)
global im;
axes(handles.axes2);
imshow(im);