Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

imregdemons

Estimate displacement field that aligns two 2-D or 3-D images

Syntax

[D,moving_reg] = imregdemons(moving,fixed)
[___] = imregdemons(moving,fixed,N)
[gpuarrayD,gpuarrayMoving_reg] = imregdemons(gpuarrayMoving,gpuarrayFixed,N)
[___] = imregdemons(___,Name,Value,...)

Description

example

[D,moving_reg] = imregdemons(moving,fixed) estimates the displacement field D that aligns the image to be registered, moving, with the reference image, fixed. moving and fixed are 2-D or 3-D intensity images.

The displacement vectors at each pixel location map locations from the fixed image grid to a corresponding location in the moving image. moving_reg is a warped version of the moving image that is warped according to the displacement field D and resampled using linear interpolation.

[___] = imregdemons(moving,fixed,N) specifies the number of iterations to be computed. This function does not use a convergence criterion and therefore is always guaranteed to run for the specified or default number of iterations.

example

[gpuarrayD,gpuarrayMoving_reg] = imregdemons(gpuarrayMoving,gpuarrayFixed,N) performs the estimation on a GPU.

example

[___] = imregdemons(___,Name,Value,...) registers the moving image using name-value pairs to control aspects of weight computation.

Examples

collapse all

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.

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')

Perform a nonrigid registration on a GPU.

Read images into the workspace.

fixed  = imread('hands1.jpg');
moving = imread('hands2.jpg');

Observe the initial misalignment. (Fingers are in different positions.)

figure
imshowpair(fixed,moving,'montage')
figure
imshowpair(fixed,moving)

Create gpuArrays and convert the images to grayscale.

fixedGPU  = gpuArray(fixed);
movingGPU = gpuArray(moving);
 
fixedGPU  = rgb2gray(fixedGPU);
movingGPU = rgb2gray(movingGPU);

Use histogram matching to correct illumination differences between the moving and fixed images. This is a common preprocessing step.

fixedHist = imhist(fixedGPU);
movingGPU = histeq(movingGPU,fixedHist);

Perform the registration.

[~,movingReg] = imregdemons(movingGPU,fixedGPU,[500 400 200],'AccumulatedFieldSmoothing',1.3);

Bring the registered image back to the CPU.

 movingReg = gather(movingReg);

View the results.

figure
imshowpair(fixed,movingReg)
figure
imshowpair(fixed,movingReg,'montage')

Input Arguments

collapse all

Image to be registered, specified as a 2-D or 3-D grayscale image.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

Reference image in the target orientation, specified as a 2-D or 3-D grayscale image.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

Number of iterations, specified as a positive integer scalar or vector.

When you specify a vector, N is the number of iterations per pyramid level (resolution level). For example, if there are 3 pyramid levels, you can specify the vector [100,50,25], where imregdemons performs 100 iterations at the lowest resolution level, 50 iterations at the next pyramid level, and 25 iterations at the last iteration level—the level with full resolution. Because it takes less time to process the lower resolution levels, running more iterations at low resolution and fewer iterations at the higher resolutions of the pyramid can help performance.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32

Input image for processing on a GPU, specified as a 2-D or 3-D grayscale image.

Reference image for processing on a GPU, specified as a gpuArray containing 2-D or 3-D grayscale image.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: [D,movingReg] = imregdemons(moving,fixed,[500 400 200],'AccumulatedFieldSmoothing',1.5);

collapse all

Smoothing applied at each iteration, specified as the comma-separated pair consisting of 'AccumulatedFieldSmoothing' and a numeric value. This parameter controls the amount of diffusion-like regularization.imregdemons applies the standard deviation of the Gaussian smoothing to regularize the accumulated field at each iteration. Larger values result in smoother output displacement fields. Smaller values result in more localized deformation in the output displacement field. Values typically are in the range [0.5, 3.0]. When you specify multiple PyramidLevels, the standard deviation used in the Gaussian smoothing remains the same at each pyramid level.

Data Types: double

Number of multi-resolution image pyramid levels to use, specified as the comma-separated pair consisting of 'PyramidLevels' and a positive integer scalar.

Data Types: double

Display waitbar to indicate progress, specified as the comma-separated pair consisting of 'DisplayWaitbar' and the value true or false. When set to true, imregdemons displays a waitbar to indicate progress for long-running operations. To prevent imregdemons from displaying a waitbar, set DisplayWaitbar to false.

Note

The 'DisplayWaitbar' parameter is not supported on a GPU.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Output Arguments

collapse all

Displacement field, specified as a numeric array. Displacement values are in units of pixels.

  • If fixed is a 2-D grayscale image of size m-by-n, the displacement field array is m-by-n-by-2. D(:,:,1) contains displacements along the x-axis and D(:,:,2) contains displacements along the y-axis.

  • If fixed is a 3-D grayscale image of size m-by-n-by-p, the displacement field array is m-by-n-by-p-by-3. D(:,:,:,1) contains displacements along the x-axis, D(:,:,:,2) contains displacements along the y-axis. and D(:,:,:,3) contains displacements along the z-axis.

Data Types: double

Registered image, returned as a 2-D or 3-D grayscale image, warped according to the displacement field D and resampled using linear interpolation.

Displacement field, specified as a gpuArray containing a matrix of class double.

Registered image, returned as a gpuArray containing a 2-D or 3-D grayscale image, warped according to the displacement field gpuarrayD and resampled using linear interpolation.

Tips

  • To transform an image using the displacement field D, use imwarp.

Introduced in R2014b

Was this topic helpful?