(1)设计MATLAB图形界面,包括参考影像、带配准影像文件读取,控制点存储,配准后的影像写入等功能。 (2)根据课堂讲授的关于人工选取控制点的配准方法,设计基于人工选取控制点的配准程序; (3)研究基于Harris角点、相关系数法等遥感影像配准方法,设计自动提取控制点,并实现遥感影像配准。
时间: 2024-03-20 12:45:15 浏览: 81
以下是基于MATLAB图形界面的遥感图像配准程序代码:
```matlab
function varargout = imageRegistrationGUI(varargin)
% IMAGE REGISTRATION GUI MATLAB code for imageRegistrationGUI.fig
% IMAGE REGISTRATION GUI, by itself, creates a new IMAGE REGISTRATION GUI or raises the existing
% singleton*.
%
% H = IMAGE REGISTRATION GUI returns the handle to a new IMAGE REGISTRATION GUI or the handle to
% the existing singleton*.
%
% IMAGE REGISTRATION GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMAGE REGISTRATION GUI.M with the given input arguments.
%
% IMAGE REGISTRATION GUI('Property','Value',...) creates a new IMAGE REGISTRATION GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before imageRegistrationGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to imageRegistrationGUI_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 imageRegistrationGUI
% Last Modified by GUIDE v2.5 29-Jun-2021 16:31:49
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @imageRegistrationGUI_OpeningFcn, ...
'gui_OutputFcn', @imageRegistrationGUI_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 imageRegistrationGUI is made visible.
function imageRegistrationGUI_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 imageRegistrationGUI (see VARARGIN)
% Choose default command line output for imageRegistrationGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes imageRegistrationGUI wait for user response (see UIRESUME)
% uiwait(handles.imageRegistrationGUI);
% --- Outputs from this function are returned to the command line.
function varargout = imageRegistrationGUI_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 browseFixedImageBtn.
function browseFixedImageBtn_Callback(hObject, eventdata, handles)
% hObject handle to browseFixedImageBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Allow user to select fixed image file
[filename, pathname] = uigetfile({'*.tif;*.tiff;*.jpg;*.jpeg;*.bmp;*.png','All Image Files';...
'*.*','All Files'}, 'Select Fixed Image File');
if isequal(filename,0) || isequal(pathname,0)
return;
else
handles.fixedImageFile = fullfile(pathname, filename);
set(handles.fixedImageFilePath, 'String', handles.fixedImageFile);
end
% Update handles structure
guidata(hObject, handles);
function fixedImageFilePath_Callback(hObject, eventdata, handles)
% hObject handle to fixedImageFilePath (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 fixedImageFilePath as text
% str2double(get(hObject,'String')) returns contents of fixedImageFilePath as a double
% --- Executes during object creation, after setting all properties.
function fixedImageFilePath_CreateFcn(hObject, eventdata, handles)
% hObject handle to fixedImageFilePath (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in browseMovingImageBtn.
function browseMovingImageBtn_Callback(hObject, eventdata, handles)
% hObject handle to browseMovingImageBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Allow user to select moving image file
[filename, pathname] = uigetfile({'*.tif;*.tiff;*.jpg;*.jpeg;*.bmp;*.png','All Image Files';...
'*.*','All Files'}, 'Select Moving Image File');
if isequal(filename,0) || isequal(pathname,0)
return;
else
handles.movingImageFile = fullfile(pathname, filename);
set(handles.movingImageFilePath, 'String', handles.movingImageFile);
end
% Update handles structure
guidata(hObject, handles);
function movingImageFilePath_Callback(hObject, eventdata, handles)
% hObject handle to movingImageFilePath (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 movingImageFilePath as text
% str2double(get(hObject,'String')) returns contents of movingImageFilePath as a double
% --- Executes during object creation, after setting all properties.
function movingImageFilePath_CreateFcn(hObject, eventdata, handles)
% hObject handle to movingImageFilePath (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in selectControlPointsBtn.
function selectControlPointsBtn_Callback(hObject, eventdata, handles)
% hObject handle to selectControlPointsBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Read fixed image and moving image
fixedImage = imread(handles.fixedImageFile);
movingImage = imread(handles.movingImageFile);
% Display the two images
axes(handles.fixedImageAxes);
imshow(fixedImage);
title('Fixed Image');
axes(handles.movingImageAxes);
imshow(movingImage);
title('Moving Image');
% Allow user to manually select control points
[fixedPoints,movingPoints] = cpselect(fixedImage,movingImage,'Wait',true);
% Store control points in handles
handles.fixedPoints = fixedPoints;
handles.movingPoints = movingPoints;
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in registerImageBtn.
function registerImageBtn_Callback(hObject, eventdata, handles)
% hObject handle to registerImageBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Read fixed image and moving image
fixedImage = imread(handles.fixedImageFile);
movingImage = imread(handles.movingImageFile);
% Retrieve control points from handles
fixedPoints = handles.fixedPoints;
movingPoints = handles.movingPoints;
% Perform image registration using control points
tform = fitgeotrans(movingPoints, fixedPoints, 'affine');
registeredImage = imwarp(movingImage, tform, 'OutputView', imref2d(size(fixedImage)));
% Display the registered image
axes(handles.registeredImageAxes);
imshow(registeredImage);
title('Registered Image');
% Save the registered image
[filename, pathname] = uiputfile({'*.tif;*.tiff;*.jpg;*.jpeg;*.bmp;*.png','All Image Files';...
'*.*','All Files'}, 'Save Registered Image As', 'registeredImage.tif');
if isequal(filename,0) || isequal(pathname,0)
return;
else
imwrite(registeredImage, fullfile(pathname, filename));
end
% --- Executes on button press in autoSelectControlPointsBtn.
function autoSelectControlPointsBtn_Callback(hObject, eventdata, handles)
% hObject handle to autoSelectControlPointsBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Read fixed image and moving image
fixedImage = imread(handles.fixedImageFile);
movingImage = imread(handles.movingImageFile);
% Detect Harris corners in fixed image and moving image
fixedPoints = detectHarrisFeatures(fixedImage);
movingPoints = detectHarrisFeatures(movingImage);
% Extract features in the fixed image and moving image
[fixedFeatures, fixedPoints] = extractFeatures(fixedImage, fixedPoints);
[movingFeatures, movingPoints] = extractFeatures(movingImage, movingPoints);
% Match features between the fixed image and moving image
indexPairs = matchFeatures(fixedFeatures, movingFeatures);
% Retrieve matched points in the fixed image and moving image
fixedPoints = fixedPoints(indexPairs(:,1),:);
movingPoints = movingPoints(indexPairs(:,2),:);
% Store control points in handles
handles.fixedPoints = fixedPoints.Location;
handles.movingPoints = movingPoints.Location;
% Update handles structure
guidata(hObject, handles);
% Display the two images and the matched points
axes(handles.fixedImageAxes);
imshow(fixedImage);
hold on;
plot(fixedPoints);
title('Fixed Image with Control Points');
axes(handles.movingImageAxes);
imshow(movingImage);
hold on;
plot(movingPoints);
title('Moving Image with Control Points');
% --- Executes on button press in clearControlPointsBtn.
function clearControlPointsBtn_Callback(hObject, eventdata, handles)
% hObject handle to clearControlPointsBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Clear control points from handles
handles = rmfield(handles, 'fixedPoints');
handles = rmfield(handles, 'movingPoints');
% Clear control point displays
axes(handles.fixedImageAxes);
cla;
title('');
axes(handles.movingImageAxes);
cla;
title('');
% Update handles structure
guidata(hObject, handles);
```
以上是基于图形界面的MATLAB遥感图像配准程序,其中包含了参考影像、待配准影像文件读取,控制点存储,配准后的影像写入等功能。此外,该程序还包含了基于人工选取控制点和基于Harris角点自动提取控制点两种配准方法。完整的代码可以在MATLAB中创建GUI后,在GUIDE中编辑生成。
阅读全文