1 简介
基于最大化互信息的配准方法因其复杂性高而不能满足临床的实时性要求;基于光流场模型的图像配准方法计算简单快速,但已有的采用光流场进行配准的方法都直接采用原始的Horn模型,该模型简单地采用速度场的模作为光滑性约束,而导致配准过程不能保持图像的不连续性,使得图像严重模糊以致无法应用,该模型还存在不能处理大位移的问题.为了能在配准过程中尽可能地保持图像特征,采用了Lucas等人提出的窗口化光流场模型,通过选用小的窗口减轻对图像造成的模糊;对于大位移问题,可以采用金字塔结构来有效处理.实验结果证明,Lucas光流场模型应用于医学图像配准能够得到较准确的配准结果,具有很高的运行效率.
2 部分代码
function varargout = optical_flow(varargin)
% OPTICAL_FLOW M-file for optical_flow.fig
% OPTICAL_FLOW, by itself, creates a new OPTICAL_FLOW or raises the existing
% singleton*.
%
% H = OPTICAL_FLOW returns the handle to a new OPTICAL_FLOW or the handle to
% the existing singleton*.
%
% OPTICAL_FLOW('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in OPTICAL_FLOW.M with the given input arguments.
%
% OPTICAL_FLOW('Property','Value',...) creates a new OPTICAL_FLOW or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before optical_flow_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to optical_flow_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 optical_flow
% Last Modified by GUIDE v2.5 23-Jul-2012 15:10:21
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @optical_flow_OpeningFcn, ...
'gui_OutputFcn', @optical_flow_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 optical_flow is made visible.
function optical_flow_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 optical_flow (see VARARGIN)
% Choose default command line output for optical_flow
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes optical_flow wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = optical_flow_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 on button press in pushbutton_start.
function pushbutton_start_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global FilePath1
global FilePath2
global version
if ( isequal(FilePath1,'No Picture') || isequal(FilePath2,'No Picture') )
errordlg('选择图片出错!','MATLAB error');
return
end
switch version
case { 0, 1, 2 }
optic_flow_brox(FilePath1, FilePath2);
case 3
Horn_WJY(FilePath2, FilePath1);
case 4
Lucas_Kanade(FilePath2, FilePath1);
otherwise
errordlg('选择算法出错!','MATLAB error');
end
% --- Executes on button press in pushbutton_pic1.
function pushbutton_pic1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_pic1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global FilePath1
[FileName,PathName] = uigetfile({'*.jpg';'*.bmp'},'Select the picture');
if ~isequal(FileName,0)
FilePath1 = fullfile(PathName,FileName);
set(handles.edit_lj1,'String',FilePath1);
img=imread(FilePath1);
axes(handles.axes_pic1);
imshow(img);
end
guidata(hObject, handles);
% --- Executes on button press in pushbutton_pic2.
function pushbutton_pic2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_pic2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global FilePath2
[FileName,PathName] = uigetfile({'*.jpg';'*.bmp'},'Select the picture');
if ~isequal(FileName,0)
FilePath2 = fullfile(PathName,FileName);
set(handles.edit_lj2,'String',FilePath2);
img=imread(FilePath2);
axes(handles.axes_pic2);
imshow(img);
end
guidata(hObject, handles);
function edit_lj1_Callback(hObject, eventdata, handles)
% hObject handle to edit_lj1 (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 edit_lj1 as text
% str2double(get(hObject,'String')) returns contents of edit_lj1 as a double
% --- Executes during object creation, after setting all properties.
function edit_lj1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_lj1 (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 edit_lj2_Callback(hObject, eventdata, handles)
% hObject handle to edit_lj2 (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 edit_lj2 as text
% str2double(get(hObject,'String')) returns contents of edit_lj2 as a double
% --- Executes during object creation, after setting all properties.
function edit_lj2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_lj2 (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 edit_arithmetic_Callback(hObject, eventdata, handles)
% hObject handle to edit_arithmetic (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 edit_arithmetic as text
% str2double(get(hObject,'String')) returns contents of edit_arithmetic as a double
% --- Executes during object creation, after setting all properties.
function edit_arithmetic_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_arithmetic (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 uipanel_choice_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to uipanel_choice (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global version
if get(handles.radiobutton_horn,'Value')
s=1;
end
if get(handles.radiobutton_lk,'Value')
s=2;
end
if get(handles.radiobutton_brox,'Value')
s=3;
end
if get(handles.radiobutton_bs,'Value')
s=4;
end
if get(handles.radiobutton_bss,'Value')
s=5;
end
switch s
case 1
version = 3;
set(handles.edit_arithmetic,'String','Horn-Schunck');
case 2
version = 4;
set(handles.edit_arithmetic,'String','Lucas-Kanade');
case 3
version = 0;
set(handles.edit_arithmetic,'String','Brox');
case 4
version = 1;
set(handles.edit_arithmetic,'String','Brox 改进版本');
case 5
version = 2;
set(handles.edit_arithmetic,'String','Brox 改进版本 + Sift');
end
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function pushbutton_start_CreateFcn(hObject, eventdata, handles)
% hObject handle to pushbutton_start (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 figure1_CreateFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
addpath('./Brox');
addpath('./Horn_Schunck');
addpath('./Lucas_Kanade');
global version
global FilePath1
global FilePath2
version = 3;
FilePath1 = 'No Picture';
FilePath2 = 'No Picture';
3 仿真结果
4 参考文献
[1]苏孟超. 基于SURF和光流场的多模态医学图像配准技术研究[D]. 南昌航空大学, 2019.
5 MATLAB代码与数据下载地址
见博客主页