先上图吧:
这个是界面效果图:(一律下拉菜单)
图像滤波效果图:
代码:
以下这是.m文件(fig文件在资源里,可以免费下载弱弱的加一句,其实资源里也有这个.m文件,呵呵)
function varargout = tuxiangchuli(varargin)
% GUIDETEMPLATE0 M-file for guidetemplate0.fig
% GUIDETEMPLATE0, by itself, creates a new GUIDETEMPLATE0 or raises the existing
% singleton*.
%
% H = GUIDETEMPLATE0 returns the handle to a new GUIDETEMPLATE0 or the handle to
% the existing singleton*.
%
% GUIDETEMPLATE0('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUIDETEMPLATE0.M with the given input arguments.
%
% GUIDETEMPLATE0('Property','Value',...) creates a new GUIDETEMPLATE0 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before guidetemplate0_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to guidetemplate0_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help guidetemplate0
% Last Modified by GUIDE v2.5 08-Jan-2013 14:12:19
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @tuxiangchuli_OpeningFcn, ...
'gui_OutputFcn', @tuxiangchuli_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
% End initialization code - DO NOT EDIT
% --- Executes just before guidetemplate0 is made visible.
function tuxiangchuli_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 guidetemplate0 (see VARARGIN)
% Choose default command line output for guidetemplate0
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes guidetemplate0 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = tuxiangchuli_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
% --- Executes during object creation, after setting all properties.
function axes2_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes2
% --------------------------------------------------------------------
function file_Callback(hObject, eventdata, handles)
% hObject handle to file (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function openfile_Callback(hObject, eventdata, handles)
% hObject handle to openfile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global x;
[name,path]=uigetfile('*.*','');
file=[path,name];
axes(handles.axes1);
x=imread(file);
handles.img=x;
guidata(hObject, handles);
imshow(x);
% --------------------------------------------------------------------
function savefile_Callback(hObject, eventdata, handles)
% hObject handle to savefile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.axes2,'HandleVisibility','ON');
axes(handles.axes2);
[filename,pathname]=uiputfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'save image as');
file=strcat(pathname,filename);
i=getimage(gca);
imwrite(i,file);
set(handles.axes2,'HandleVisibility','Off');
% --------------------------------------------------------------------
function exit_Callback(hObject, eventdata, handles)
% hObject handle to exit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc;
close all;
close('gcf');
% --- Executes on button press in ReloadRecentImage.
function ReloadRecentImage_Callback(hObject, eventdata, handles)
% hObject handle to ReloadRecentImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% x=(handles.img);
% [row,col,Cnums]=size(x);
% axes(handles.axes2);
% imshow(zeros([256,256]));
% if Cnums==1
% if (row<=256)&(col<=256)
% W=256;
% else
% W=max(row,col);
% end
% for m=1:W
% for n=1:W
% if (m<=row)&(n<=col)
% extendx(m,n)=x(m,n);
% else
% extendx(m,n)=realmax;
% end
% end
% end
% axes(handles.axes1);
% Imshow(extendx);
% else
% if (row<=256)&(col<=256)
% W=256;
% else
% W=max(row,col);
% end
% for m=1:W
% for n=1:W
% if (m<=row)&(n<=col)
% extendx(m,n,:)=x(m,n,:);
% else
% extendx(m,n,:)=realmax;
% end
% end
% end
%
% % Imshow(extendx);
%
% msgbox('Please transform it to a monochrome image or it can not be processed correctly','fileopening','warning');
% end
% axes(handles.axes1);
% Imshow(extendx);
% guidata(hObject, handles);
global x;
set(handles.axes2,'HandleVisibility','on');
axes(handles.axes2);
y=getimage(gca);
axes(handles.axes1);
imshow(y);
set(handles.axes2,'HandleVisibility','off');
% --------------------------------------------------------------------
function edit_Callback(hObject, eventdata, handles)
% hObject handle to edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function liangdu_Callback(hObject, eventdata, handles)
% hObject handle to liangdu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes2);
set(handles.axes2,'HandleVisibility','ON');
prompt={'insert1','insert2','insert gamma'};
defans={'[0 0.7]','[0 1]','1'};
p=inputdlg(prompt,'insert',1,defans);
p1=str2num(p{1});
p2=str2num(p{2});
p3=str2num(p{3});
gamma=p3;
global x;
y=imadjust(x,p1,p2,gamma);
imshow(y);
set(handles.axes2,'HandleVisibility','Off');
% --------------------------------------------------------------------
function style_Callback(hObject, eventdata, handles)
% hObject handle to style (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function suoyinse_Callback(hObject, eventdata, handles)
% hObject handle to suoyinse (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global x;
axes(handles.axes2);
set(handles.axes2,'HandleVisibility','ON');
y=grayslice(x,64);
imshow(y);
set(handles.axes2,'HandleVisibility','Off');
% --------------------------------------------------------------------
function erzhitu_Callback(hObject, eventdata, handles)
% hObject handle to erzhitu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global x;
axes(handles.axes2);
set(handles.axes2,'HandleVisibility','ON');
y=im2bw(x,0.4);
imshow(y);
set(handles.axes2,'HandleVisibility','Off');
% --------------------------------------------------------------------
function huidu_Callback(hObject, eventdata, handles)
% hObject handle to huidu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global x;
axes(handles.axes2);
set(handles.axes2,'HandleVisibility','ON');
if isrgb(x)
im=rgb2gray(x);
imshow(im);
handles.img=im;
else
msgbox('it is a gray picture','failure');
end
guidata(hObject,handles);
set(handles.axes2,'HandleVisibility','Off');
% --------------------------------------------------------------------
function jietu_Callback(hObject, eventdata, handles)
% hObject handle to jietu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.axes2,'HandleVisibility','ON');
y=imcrop(handles.img);
imshow(y);
axes(handles.axes2);
imwrite(y,'jietu.jpg');
handles.Timage=y;
set(handles.axes2,'HandleVisibility','OFF');
% --- Executes on slider movement.
function liangdutiaojietiao_Callback(hObject, eventdata, handles)
% hObject handle to liangdutiaojietiao (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of