www.gusucode.com > images 案例代码 matlab源码程序 > images/RegisterTwoMisalignedImagesExample.m

    %% Register Two Images with Local Distortions
% This example shows how to solve a registration problem in which the same
% hand has been photographed in two different poses. The misalignment of
% the images varies locally throughout each image. This is therefore a
% non-rigid registration problem.
%%
% Read the two images into the workspace.

% Copyright 2015 The MathWorks, Inc.

fixed  = imread('hands1.jpg');
moving = imread('hands2.jpg');
%%
% Convert the images to grayscale for processing.
fixed  = rgb2gray(fixed);
moving = rgb2gray(moving);
%%
% Observe the initial misalignment. Fingers are in different poses. In the
% second figure, the two images are overlaid over each other to make it
% easy to see where the images differ. The differences are highlighted in
% green.
figure
imshowpair(fixed,moving,'montage')
figure
imshowpair(fixed,moving)
%%
% Correct illumination differences between the |moving| and |fixed| images
% using histogram matching. This is a common pre-processing step.
moving = imhistmatch(moving,fixed);
%%
% Estimate the transformation needed to bring the two images into
% alignment.
[~,movingReg] = imregdemons(moving,fixed,[500 400 200],...
    'AccumulatedFieldSmoothing',1.3);
%%
% Display the results of the registration. In the first figure, the images
% are overlaid to show the alignment. 
figure
imshowpair(fixed,movingReg)
figure
imshowpair(fixed,movingReg,'montage')