gusucode.com > matlab gui界面设计,包括:图像的剪切和显示,彩色图像灰度直方图获取;灰度直方图,直方图均衡化和直方图匹配 > hanfeng612.m
function varargout = hanfeng612(varargin) % HANFENG612 M-file for hanfeng612.fig % HANFENG612, by itself, creates a New HANFENG612 or raises the existing % singleton*. % % H = HANFENG612 returns the handle to a New HANFENG612 or the handle to % the existing singleton*. % % HANFENG612('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in HANFENG612.M with the given input arguments. % % HANFENG612('Property','Value',...) creates a New HANFENG612 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before hanfeng612_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to hanfeng612_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 % Edit the above text to modify the response to help hanfeng612 % Last Modified by GUIDE v2.5 12-Apr-2010 16:52:31 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @hanfeng612_OpeningFcn, ... 'gui_OutputFcn', @hanfeng612_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 hanfeng612 is made visible. function hanfeng612_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) set(handles.radiobutton1,'value',0); set(handles.radiobutton2,'value',0); set(handles.radiobutton3,'value',0); set(handles.radiobutton4,'value',0); set(handles.radiobutton5,'value',0); % varargin command line arguments to hanfeng612 (see VARARGIN) % Choose default command line output for hanfeng612 handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes hanfeng612 wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = hanfeng612_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; % -------------------------------------------------------------------- function Untitled_1_Callback(hObject, eventdata, handles) % hObject handle to Untitled_1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_2_Callback(hObject, eventdata, handles) % hObject handle to Untitled_2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; [filename,pathname]=uigetfile({'*.*';'*.bmp';'*.tif';'*.png'},'select picture'); str=[pathname filename]; A=imread(str); axes(handles.axes3); imshow(A); % -------------------------------------------------------------------- function Untitled_3_Callback(hObject, eventdata, handles) % hObject handle to Untitled_3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close(gcf) % -------------------------------------------------------------------- function Untitled_10_Callback(hObject, eventdata, handles) % hObject handle to Untitled_10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_4_Callback(hObject, eventdata, handles) % hObject handle to Untitled_4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function Untitled_5_Callback(hObject, eventdata, handles) % hObject handle to Untitled_5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; BST=edge(A,'robert'); axes(handles.New); imshow(BST); % -------------------------------------------------------------------- function Untitled_6_Callback(hObject, eventdata, handles) % hObject handle to Untitled_6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; SST=edge(A,'sobel'); axes(handles.New); imshow(SST); % -------------------------------------------------------------------- function Untitled_7_Callback(hObject, eventdata, handles) % hObject handle to Untitled_7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; PST=edge(A,'prewitt'); axes(handles.New); imshow(PST); % -------------------------------------------------------------------- function Untitled_8_Callback(hObject, eventdata, handles) % hObject handle to Untitled_8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; CAN=edge(A,'canny'); axes(handles.New); imshow(CAN); % -------------------------------------------------------------------- function Untitled_9_Callback(hObject, eventdata, handles) % hObject handle to Untitled_9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; LST=edge(A,'log'); axes(handles.New); imshow(LST); % -------------------------------------------------------------------- function Untitled_11_Callback(hObject, eventdata, handles) % hObject handle to Untitled_11 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; B=imcrop(A); axes(handles.New); imshow(B); % -------------------------------------------------------------------- function Untitled_12_Callback(hObject, eventdata, handles) % hObject handle to Untitled_12 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; KF=fftshift(fft2(A)); axes(handles.New); imshow(KF); % --- 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) global A; A=double(A); H=floor(A/32); H1=floor(H/4); H2=rem(floor(H/2),2); H3=rem(H,2); HD(:,:,1)=H1; HD(:,:,2)=H2; HD(:,:,3)=H3; axes(handles.New); imshow(HD); % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; k=fft2(A); g=fftshift(k); [N1,N2]=size(g); n=2; d0=12; w=16; n1=round(N1/2); n2=round(N2/2); for i=1:N1 for j=1:N2 d=sqrt((i-n1)^2+(j-n2)^2); d1=d0-w/2; d2=d0+w/2; if (d<=d1)|(d>=d2) h=0; else h=1; end y1(i,j)=h*g(i,j); end end y1=ifftshift(y1); E0=ifft2(y1); d1=50; for i=1:N1 for j=1:N2 d=sqrt((i-n1)^2+(j-n2)^2); if d<=d1; h=0; else h=1; end y2(i,j)=h*g(i,j); end end y2=ifftshift(y2); E4=ifft2(y2); d2=2; n1=round(N1/2); n2=round(N2/2); for i=1:N1 for j=1:N2 d=sqrt((i-n1)^2+(j-n2)^2); if d<=d2; h=1; else h=0; end y3(i,j)=h*g(i,j); end end y3=ifftshift(y3); E5=ifft2(y3); Z(:,:,1)=E5; Z(:,:,2)=E0; Z(:,:,3)=E4; axes(handles.New); imshow(Z); % --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A f=double(A); g=fft2(f); g=fftshift(g); [N1,N2]=size(g); n=2; d0=10; %此处d0为截止频率,可以依次换成60、70、80进行滤波比较 n1=fix(N1/2); n2=fix(N2/2); for i=1:N1 for j=1:N2 d=sqrt((i-n1)^2+(j-n2)^2); h=1/(1+0.414*(d/d0)^(2*n)); result(i,j)=h*g(i,j); end end result=ifftshift(result); DT=ifft2(result); DTL=uint8(real(DT)); axes(handles.New); imshow(DTL); % --- Executes on button press in pushbutton6. function pushbutton6_Callback(hObject, eventdata, handles) % hObject handle to pushbutton6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; axes(handles.New); imhist(A); % --- Executes on button press in pushbutton7. function pushbutton7_Callback(hObject, eventdata, handles) % hObject handle to pushbutton7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A C=histeq(A); axes(handles.New); imshow(C); % --- Executes on button press in pushbutton8. function pushbutton8_Callback(hObject, eventdata, handles) % hObject handle to pushbutton8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A hgram=40:2:200;%匹配函数 C1=histeq(A,hgram); axes(handles.New); imshow(C1); % --- Executes on button press in pushbutton9. function pushbutton9_Callback(hObject, eventdata, handles) % hObject handle to pushbutton9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A D=im2bw(A); axes(handles.New); imshow(D); % --- Executes on button press in radiobutton1. function radiobutton1_Callback(hObject, eventdata, handles) % hObject handle to radiobutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; se = strel('disk',5); I_opened = imopen(A,se); axes(handles.New); imshow(I_opened,[]) % Hint: get(hObject,'Value') returns toggle state of radiobutton1 % --- Executes on button press in radiobutton3. function radiobutton3_Callback(hObject, eventdata, handles) % hObject handle to radiobutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; D=im2bw(A); E=ones(4.5,4.5); F=imerode(D,E); axes(handles.New); imshow(F); % Hint: get(hObject,'Value') returns toggle state of radiobutton3 % --- Executes on button press in radiobutton5. function radiobutton5_Callback(hObject, eventdata, handles) % hObject handle to radiobutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; se = strel('disk',10); closeBW = imclose(A,se); imshow(closeBW); % Hint: get(hObject,'Value') returns toggle state of radiobutton5 % --- Executes on button press in radiobutton4. function radiobutton4_Callback(hObject, eventdata, handles) % hObject handle to radiobutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; D=im2bw(A); S=ones(5,5); P=imdilate(D,S); axes(handles.New); imshow(P); % Hint: get(hObject,'Value') returns toggle state of radiobutton4 % --- Executes on button press in pushbutton10. function pushbutton10_Callback(hObject, eventdata, handles) % hObject handle to pushbutton10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; GS=imnoise(A,'gaussian',0.001); axes(handles.New); imshow(GS); % --- 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) global A; val = get(hObject,'Value'); switch val case 1 GSZS=imnoise(A,'gaussian',0.001); h=fspecial('gaussian',[6 6],0.5); GSLB=imfilter(GSZS,h); axes(handles.New); imshow(GSLB); case 2 GSZS=imnoise(A,'gaussian',0.001); h=fspecial('average',3); JZLB=uint8(round(filter2(h,GSZS))); axes(handles.New); imshow(JZLB); case 3 GSZS=imnoise(A,'gaussian',0.001); ZZLB=medfilt2(GSZS,[6 6]); axes(handles.New); imshow(ZZLB); end % Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1 % --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on slider movement. function duibidubianhuan_Callback(hObject, eventdata, handles) % hObject handle to duibidubianhuan (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) dbd=get(handles.duibidubianhuan,'Value'); set(handles.duibidubianhuan,'String',dbd); global A; DBD=A*dbd; axes(handles.New); imshow(DBD); % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider % --- Executes during object creation, after setting all properties. function duibidubianhuan_CreateFcn(hObject, eventdata, handles) % hObject handle to duibidubianhuan (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end % --- Executes on slider movement. function tuxiangxuanzhuan_Callback(hObject, eventdata, handles) % hObject handle to tuxiangxuanzhuan (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) k=get(handles.tuxiangxuanzhuan,'Value'); set(handles.tuxiangxuanzhuan,'String',k); global A; XZ=imrotate(A,k,'bicubic','crop'); axes(handles.New); imshow(XZ); % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider % --- Executes during object creation, after setting all properties. function tuxiangxuanzhuan_CreateFcn(hObject, eventdata, handles) % hObject handle to tuxiangxuanzhuan (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end % --- Executes on slider movement. function tuxiangsuofang_Callback(hObject, eventdata, handles) % hObject handle to tuxiangsuofang (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; k=get(handles.tuxiangsuofang,'Value'); set(handles.tuxiangsuofang,'String',k); SF=imresize(A,k); axes(handles.New); imshow(SF); % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider % --- Executes during object creation, after setting all properties. function tuxiangsuofang_CreateFcn(hObject, eventdata, handles) % hObject handle to tuxiangsuofang (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end % --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A B; % =rgb2gray(B); a=double(A); z=fftshift(fft2(a)); [m,n]=size(z); G=zeros(m,n); for i=1:m; for j=1:n; if (i-(m/2))^2+(j-(n/2))^2>16&&(i-(m/2))^2+(j-(n/2))^2<2000 G(i,j)=1; end; end; end; bandpass=z.*G; DAT=ifft2(ifftshift(bandpass)); DATL=uint8(real(DAT)); axes(handles.New); imshow(DATL); % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; f=double(A); g=fft2(f); g=fftshift(g); [N1,N2]=size(g); n=2; d0=3; %此处d0为截止频率 n1=fix(N1/2); n2=fix(N2/2); for i=1:N1 for j=1:N2 d=sqrt((i-n1)^2+(j-n2)^2); if d==0 h=0; else h=1/(1+(d0/d)^(2*n)); end result(i,j)=h*g(i,j); end end result=ifftshift(result); GT=ifft2(result); GTL=uint8(real(GT)); axes(handles.New); imshow(GTL); % -------------------------------------------------------------------- function string_Callback(hObject, eventdata, handles) % hObject handle to string (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; T = maketform('affine',[1 0 0; 1 1 0; 0 0 1]); tformfwd([15 30],T) I2 = imtransform(A,T); set(handles.New,'HandleVisibility','ON'); axes(handles.New); imshow(I2); % -------------------------------------------------------------------- function Untitled_13_Callback(hObject, eventdata, handles) % hObject handle to Untitled_13 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A imshow(A); im1=A; im2=im1; %im1=rgb2ycbcr(im); Lu=im1(:,:,1); Cb=im1(:,:,2); Cr=im1(:,:,3); [x y z]=size(im1); tst=zeros(x,y); Mb=sum(sum(Cb)); Mr=sum(sum(Cr)); Mb=Mb/(x*y); Mr=Mr/(x*y); Db=sum(sum(Cb-Mb))/(x*y); Dr=sum(sum(Cr-Mr))/(x*y); cnt=1; for i=1:x for j=1:y b1=Cb(i,j)-(Mb+Db*sign(Mb)); b2=Cr(i,j)-(1.5*Mr+Dr*sign(Mr)); if (b1<(1.5*Db) & b2<(1.5*Dr)) Ciny(cnt)=Lu(i,j); tst(i,j)=Lu(i,j); cnt=cnt+1; end end end cnt=cnt-1; iy=sort(Ciny,'descend'); nn=round(cnt/10); Ciny2(1:nn)=iy(1:nn); mn=min(Ciny2); c=0; for i=1:x for j=1:y if tst(i,j)<mn tst(i,j)=0; else tst(i,j)=1; c=c+1; end end end R=im1(:,:,1); G=im1(:,:,2); B=im1(:,:,3); R=double(R).*tst; G=double(G).*tst; B=double(B).*tst; Rav=mean(mean(R)); Gav=mean(mean(G)); Bav=mean(mean(B)); Ymax=double(max(max(Lu)))/15; Rgain=Ymax/Rav; Ggain=Ymax/Gav; Bgain=Ymax/Bav; im1(:,:,1)=im1(:,:,1)*Rgain; im1(:,:,2)=im1(:,:,2)*Ggain; im1(:,:,3)=im1(:,:,3)*Bgain; axes(handles.New); im1show(im1,[]); % --- Executes on button press in radiobutton2. function radiobutton2_Callback(hObject, eventdata, handles) % hObject handle to radiobutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global A; BW2 = bwmorph(A,'shrink',inf); axes(handles.New); imshow(BW2) % Hint: get(hObject,'Value') returns toggle state of radiobutton2 % --- Executes during object creation, after setting all properties. function axes3_CreateFcn(hObject, eventdata, handles) % hObject handle to axes3 (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 axes3 % --- Executes during object creation, after setting all properties. function text1_CreateFcn(hObject, eventdata, handles) % hObject handle to text1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % --- Executes during object creation, after setting all properties. function pushbutton10_CreateFcn(hObject, eventdata, handles) % hObject handle to pushbutton10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called