proj.m
上传用户:xueli1969
上传日期:2022-07-27
资源大小:19k
文件大小:12k
- function varargout = proj(varargin)
- % PROJ M-file for proj.fig
- % PROJ, by itself, creates a new PROJ or raises the existing
- % singleton*.
- %
- % H = PROJ returns the handle to a new PROJ or the handle to
- % the existing singleton*.
- %
- % PROJ('CALLBACK',hObject,eventData,handles,...) calls the local
- % function named CALLBACK in PROJ.M with the given input arguments.
- %
- % PROJ('Property','Value',...) creates a new PROJ or raises the
- % existing singleton*. Starting from the left, property value pairs are
- % applied to the GUI before proj_OpeningFunction gets called. An
- % unrecognized property name or invalid value makes property application
- % stop. All inputs are passed to proj_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 proj
- % Last Modified by GUIDE v2.5 21-Sep-2005 21:51:00
- % Begin initialization code - DO NOT EDIT
- gui_Singleton = 1;
- gui_State = struct('gui_Name', mfilename, ...
- 'gui_Singleton', gui_Singleton, ...
- 'gui_OpeningFcn', @proj_OpeningFcn, ...
- 'gui_OutputFcn', @proj_OutputFcn, ...
- 'gui_LayoutFcn', [] , ...
- 'gui_Callback', []);
- if nargin & isstr(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
- addpath(pwd)
- % --- Executes just before proj is made visible.
- function proj_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 proj (see VARARGIN)
- % Choose default command line output for proj
- % 初始化界面
- handles.output = hObject;
- handles.OAname='PSO';
- handles.MIname='MI';
- handles.NumOfVar=0;
- set(handles.edit1,'visible','off');
- set(handles.edit2,'visible','off');
- set(handles.text3,'visible','off');
- set(handles.text4,'visible','off');
- % set(handles.axes1,'','off');
- % axes(handles.axes1)
- % I1=0;
- % imshow(I1)
- % axes(handles.axes2)
- % I2=0;
- % imshow(I2)
- % axes(handles.axes3)
- % I3=0;
- % imshow(I3)
- guidata(hObject, handles);
- % UIWAIT makes proj wait for user response (see UIRESUME)
- % uiwait(handles.figure1);
- % --- Outputs from this function are returned to the command line.
- function varargout = proj_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 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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- 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)
- % 最优化算法选择"PSO"和"POWELL"
popupmenu1string=get(handles.popupmenu1,'string');
- popupmenu1value=get(handles.popupmenu1,'value');
- popupmenu1context=get(handles.popupmenu1,{'value','string'});
- vvv1=deblank(popupmenu1context{2}(popupmenu1context{1}));
- handles.OAname=vvv1{1};
- guidata(hObject,handles);
% 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 popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu2 (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
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)
- % 选择互信息尺度函数(MI)
popupmenu2string=get(handles.popupmenu2,'string');
- popupmenu2value=get(handles.popupmenu2,'value');
- popupmenu2context=get(handles.popupmenu2,{'value','string'});
- vvv2=deblank(popupmenu2context{2}(popupmenu2context{1}));
- switch vvv2{1}
- case {'MI','EMI','HiMI'}
- set(handles.edit1,'visible','off');
- set(handles.edit2,'visible','off');
- set(handles.text3,'visible','off');
- set(handles.text4,'visible','off');
- NumOfVar=0; % 以上三个MI函数输入参数个数为0
- case 'RMI'
- set(handles.edit1,'visible','on','string','9');
- set(handles.edit2,'visible','off');
- set(handles.text3,'visible','on','string','size of region is 3,4,9');
- set(handles.text4,'visible','off');
- NumOfVar=1;
- case 'GMI'
- set(handles.edit1,'visible','on','string','0.5');
- set(handles.edit2,'visible','off');
- set(handles.text3,'visible','on','string','size of gussian');
- set(handles.text4,'visible','off');
- NumOfVar=1;
- case 'FPMI'
- set(handles.edit1,'visible','on','string','3');
- set(handles.edit2,'visible','on','string','null');
- set(handles.text3,'visible','on','string','size of gussian=1,2,...,15');
- set(handles.text4,'visible','on','string','0<canny threshold<1');
- NumOfVar=2;
- end
- %
- handles.NumOfVar=NumOfVar;
- handles.MIname=vvv2{1};
- guidata(hObject,handles);
% Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu2
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- 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)
- clc
- set(handles.text6,'string','Result Of Registration & MI Value');
- axesIbox=get(handles.axes2,'box');
- axesJbox=get(handles.axes3,'box');
- if strcmp(axesIbox,'off') | strcmp(axesJbox,'off')
- errordlg('请选择配准图像','错误')
- error('未选择配准图像')
- end
- handles.isSameSizeIJ=strcmp(handles.ImsizeI,handles.ImsizeJ);
- if handles.isSameSizeIJ~=1
- errordlg('请选择相同尺寸的图像','错误')
- error('配准图像大小不同')
- end
- I=imread(handles.filenameI);
- J=imread(handles.filenameJ);
- handles.I=I;
- handles.J=J;
- guidata(hObject,handles);
-
handles.edit1visible=get(handles.edit1,'visible'); % 获取窗口on、off信息
- handles.edit2visible=get(handles.edit2,'visible');
- edit1visible=strcmp(handles.edit1visible,'on');%比较字符是否相同。为了后面的判断用
- edit2visible=strcmp(handles.edit2visible,'on');
- % if handles.edit2visible=='on'
- % 如果用上面的方式判断,当遇到'off'会出错
- % error:Array dimensions must match for binary array op.
- if edit1visible==1 % 如果输入第一个参数,则获取该参数
- handles.edit1string=get(handles.edit1,'string');
- %handles.var1=str2num(handles.edit1string{1});
- handles.var1=str2num(handles.edit1string);
- end
-
- if edit2visible==1 % 如果输入第二个参数,则获取该参数
- handles.edit2string=get(handles.edit2,'string');
- %handles.var2=str2num(handles.edit2string{1});
- handles.var2=str2num(handles.edit2string);
- end
- % 整个程序的核心
- switch handles.OAname
- case 'PSO'
- out=PSO(handles);
- case 'POWELL'
- out=POWELL(handles);
- end
- handles.out=out; % 终结
- x=out(1);
- y=out(2);
- ang=out(3);
- miValue=out(4);
- FinalResult=['X,Y,Angle=',num2str(x) ',',num2str(y) ',',num2str(ang),' MI_Value=',num2str(miValue)];
- axes(handles.axes1)
- Q=restore(handles); % 获取将”固定图像“和”校正图像“的边缘重叠,以观察配准效果
- imshow(Q)
-
set(handles.text6,'string',FinalResult);
-
% --- 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)
- clc
- ValueI.ss.IsImage=0;
- while ValueI.ss.IsImage==0
- ValueI=testListBoxlj;
- end
- delete(ValueI.figure1); % 关闭浏览窗口
- handles.ImsizeI=ValueI.ss.imsize; % 图片大小(来自testlistboxij.m)
- handles.filenameI=ValueI.ss.filename; % 带路径名(来自testlistboxij.m)
- handles.names_dispI=ValueI.ss.names_disp; % 显示图片名称大小(来自testlistboxij.m)
- set(handles.text7,'String',handles.names_dispI);
- axes(handles.axes2)
- I=imread(handles.filenameI);
- imshow(I)
-
- guidata(hObject, handles);
-
% --- 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)
- clc
-
ValueJ.ss.IsImage=0;
- while ValueJ.ss.IsImage==0
- ValueJ=testListBoxlj;
- end
- delete(ValueJ.figure1); % 关闭浏览窗口
- handles.ImsizeJ=ValueJ.ss.imsize; % 图片大小(来自listbox)
- handles.filenameJ=ValueJ.ss.filename; % 带路径名(来自listbox)
- handles.names_dispJ=ValueJ.ss.names_disp; % 显示图片名称大小(来自listbox)
- set(handles.text8,'String',handles.names_dispJ); % (来自listbox)
- axes(handles.axes3)
- J=imread(handles.filenameJ);
- imshow(J)
-
- guidata(hObject, handles);