www.gusucode.com > 图像去噪的matlab的GUI界面程序实例 > code3/jiemian.m
function varargout = jiemian(varargin) % JIEMIAN Application M-file for jiemian.fig % FIG = JIEMIAN launch jiemian GUI. % JIEMIAN('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.5 04-Jun-2005 18:40:40 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try if (nargout) [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard else feval(varargin{:}); % FEVAL switchyard end catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = LoadPush_Callback(h, eventdata, handles, varargin)%回调函数 global im_original im_noised im_filtered%global:定义全局变量 [filename, pathname] = uigetfile('*.bmp;*.pgm;*.tif;*.jpg;*.*', 'Load input image');%读取文件 if isequal(filename,0) | isequal(pathname,0) disp('User pressed cancel')%disp:显示 else disp(['User selected ', fullfile(pathname, filename)]) end im_original=imread(filename); set(handles.Or_image,'HandleVisibility','OFF');%handles:句柄 set(handles.Out_image,'HandleVisibility','OFF'); %set(handles.Denoised_image,'HandleVisibility','OFF'); set(handles.Or_image,'HandleVisibility','ON'); axes(handles.Or_image); imshow(im_original); colormap(gray(256)); axis equal;%让图像的大小与框架吻合 axis tight;%同上 axis off;%把数轴关掉 set(handles.Or_image,'HandleVisibility','OFF'); set(handles.Or_image,'XTickLabel',' ','YTickLabel',' '); % -------------------------------------------------------------------- function varargout = popupmenu1_Callback(h, eventdata, handles, varargin) % -------------------------------------------------------------------- function varargout = popupmenu3_Callback(h, eventdata, handles, varargin) % -------------------------------------------------------------------- function varargout = ApplyPush_Callback(h, eventdata, handles, varargin) global im_original im_noised im_filtered imnoise_type = get(handles.popupmenu1,'Value'); % selected noise type switch imnoise_type case { 1 } %加入噪声 im_noised = gaussian_bai(im_original); %加入高斯白噪声 case { 2 } im_noised = salt(uint8(im_original)); %加入椒盐噪声 case { 3 } im_noised = speckle(uint8(im_original)); %加入乘性噪声 end method_number = get(handles.popupmenu3,'Value'); % selected filter method switch method_number case { 1 } im_filtered = meanfilter(im_noised); case { 2 } im_filtered = medfilter(im_noised); case { 3 } im_filtered = wienerfilter(im_noised); case { 4 } im_filtered = Leefilter(im_noised); case { 5 } im_filtered = Mapfilter(im_noised); case { 6 } im_filtered = Wavelethardthreshold(im_noised); case { 7 } im_filtered = Waveletsoftthreshold(im_noised); end set(handles.noised_image,'HandleVisibility','ON'); axes(handles.noised_image); imagesc(im_noised); colormap(gray(256)); axis equal; axis tight; axis off; set(handles.noised_image,'HandleVisibility','OFF') set(handles.Out_image,'HandleVisibility','ON'); axes(handles.Out_image); imagesc(im_filtered); colormap(gray(256)); axis equal; axis tight; axis off; set(handles.Out_image,'HandleVisibility','OFF') % -------------------------------------------------------------------- function varargout = QuitPush_Callback(h, eventdata, handles, varargin) clear all % to close GUI close(gcbf) % 加噪函数 function newim = gaussian_bai(img) newim = imnoise(img,'gaussian'); function newim = salt(img) newim = imnoise(img,'salt & pepper',0.02); function newim = speckle(img) newim = imnoise(img,'speckle'); % 去噪函数 function out = meanfilter(im) out = filter2(fspecial('average',3),im); %执行二维的均值滤波 function out = medfilter(im) out = medfilt2(im); %执行二维的中值滤波 function out = wienerfilter(im) % im = imnoise(I,'gaussian',0,0.005); out = wiener2(im,[5 5]); %执行二维的维纳滤波 function imout = Leefilter(x) imout=im; imout = double(imout); function imout = Mapfilter(x) imout=im; function imout = Wavelethardthreshold(x) imout=im; function out =Waveletsoftthreshold(im) %执行小波去噪 imout=im; % -------------------------------------------------------------------- function varargout = Untitled_1_Callback(h, eventdata, handles, varargin) % -------------------------------------------------------------------- function varargout = Untitled_2_Callback(h, eventdata, handles, varargin) % --- Executes on button press in Savepushbutton7. function Savepushbutton7_Callback(hObject, eventdata, handles) % hObject handle to Savepushbutton7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global im_original im_noised im_filtered [filename, pathname] = uiputfile( '*.bmp;*.pgm;*.tif;*.jpg;*.*', 'Save imagecrop image'); imwrite(im_filtered,filename); % --- Executes on button press in Saveushbutton7. function Saveushbutton7_Callback(hObject, eventdata, handles) % hObject handle to Saveushbutton7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global im_original im_noised im_filtered [filename, pathname] = uiputfile( '*.bmp;*.pgm;*.tif;*.jpg;*.*', 'Save imagecrop image'); imwrite(im_filtered,filename);