Main Content

imregdeform

Deformable registration of grayscale images or intensity volumes using total variation method

Description

The imregdeform function uses the total variation method to perform deformable registration of grayscale images or intensity volumes. You can use this function to register medical images or volumes deformed due to local transformations.

[dispField,reg] = imregdeform(moving,fixed) transforms the grayscale image or intensity volume moving, so that it is registered with the reference image or volume fixed, and returns the displacement field dispField and the registered image or volume reg.

example

[dispField,reg] = imregdeform(moving,fixed,Name=Value) specifies options for the total variation method using one or more optional name-value arguments.

Examples

collapse all

Load a reference image and an image to be registered into the workspace. Convert the images to grayscale.

fixedImg = imread("hands1.jpg");
fixed = im2gray(fixedImg);
movingImg = imread("hands2.jpg");
moving = rgb2gray(movingImg);

Display the fixed image and the moving image. Observe the deformation in the alignment of the images.

figure
imshowpair(fixed,moving)

Figure contains an axes object. The axes object contains an object of type image.

Register the moving image to the fixed image.

[dispField,reg] = imregdeform(moving,fixed,NumPyramidLevels=6,GridRegularization=0.6);
--------------------------- Pyramid Level = 6 -------------------------------- 
               Normalized     Function local                          Closeness to
 Iteration        rmse            minima          Step-size        optimal solution
     1          1.64147          37024.85           4.19                49.62783
     2          1.48633          31590.32          24.34                48.04233
     3          1.63155          30339.11          18.00                46.47121
     4          1.33748          29085.22           7.83                60.12520
     5          1.29691          28578.16          10.20                74.34988
     6          1.35689          28002.80          14.17                78.68985
     7          1.36835          27701.23           7.44                65.67400
     8          1.17573          27384.96           8.51                35.42655
     9          1.08997          26944.82          13.44                53.24290
    10          0.95153          26374.55           5.58                29.71761
    11          0.91025          26169.77           2.55                26.32110
    12          0.91195          25891.90           5.95                34.23311
    13          1.14507          25726.65          14.50                41.34727
    14          1.22759          25281.23          11.61                33.04872
    15          0.97035          24703.21           7.40                34.35227
    16          1.03194          24307.52           9.90                34.04009
    17          1.03114          24077.92           7.69                41.98692
    18          0.98282          23736.04          14.83                46.11518
    19          0.95928          23317.39          14.87                37.88543
    20          0.92435          22891.46          17.10                45.98425
    21          0.81884          22398.19          11.15                37.09230
    22          0.70854          22097.88           6.20                23.16606
    23          0.65405          21979.78           3.92                20.64745
    24          0.58632          21890.52           3.22                17.18440
    25          0.59774          21767.81           7.38                17.62879
    26          0.63929          21698.98           8.36                22.69476
    27          0.50519          21574.89           2.62                15.70961
    28          0.50145          21491.14           3.01                12.74984
    29          0.50583          21419.94           3.16                14.86162
    30          0.48495          21390.37           4.85                13.89448
    31          0.46792          21363.09           1.43                13.67136
    32          0.40962          21356.92           1.65                 9.81103
    33          0.40800          21356.83           0.18                 9.50099

--------------------------- Pyramid Level = 5 -------------------------------- 
               Normalized     Function local                          Closeness to
 Iteration        rmse            minima          Step-size        optimal solution
     1          0.44400          23959.26           5.30                22.96675
     2          0.39054          23254.00           9.46                18.54226
     3          0.36834          23134.24           5.02                22.51686
     4          0.33450          23051.56           1.59                12.51227
     5          0.33048          23004.59           2.58                10.00633
     6          0.32744          22960.51           3.02                 8.53760
     7          0.35590          22882.32           6.67                25.78811
     8          0.32620          22788.98           1.99                10.72627
     9          0.31109          22735.69           1.69                 7.66283
    10          0.30765          22695.63           2.81                 6.17570
    11          0.30926          22686.24           1.23                 7.16721
    12          0.31211          22682.41           0.80                 6.14514
    13          0.31531          22680.85           0.64                 4.67112
    14          0.31613          22680.72           0.19                 4.48773

--------------------------- Pyramid Level = 4 -------------------------------- 
               Normalized     Function local                          Closeness to
 Iteration        rmse            minima          Step-size        optimal solution
     1          0.28145          28405.52           4.99                21.00908
     2          0.26476          27597.03           9.61                12.38693
     3          0.24598          27383.91           4.02                15.36024
     4          0.23363          27324.84           1.62                 7.73944
     5          0.23838          27210.31           2.64                 5.38586
     6          0.23927          27069.79           3.11                 8.21936
     7          0.24557          26887.38           5.87                15.04406
     8          0.23496          26800.32           1.50                 8.34007
     9          0.23145          26768.71           1.57                 4.85061
    10          0.23168          26719.01           2.55                 6.54153
    11          0.23681          26642.15           5.61                15.08833
    12          0.23464          26630.58           0.24                13.59408
    13          0.23266          26610.13           0.46                10.57860
    14          0.23255          26601.49           0.22                 9.64826

--------------------------- Pyramid Level = 3 -------------------------------- 
               Normalized     Function local                          Closeness to
 Iteration        rmse            minima          Step-size        optimal solution
     1          0.16744          30346.55           7.61                 9.96175
     2          0.16423          30102.90           4.35                 8.32035
     3          0.16156          29980.10           2.71                 5.30050
     4          0.16202          29875.25           3.51                 5.31045
     5          0.16292          29776.73           4.77                 7.43416
     6          0.16392          29666.28           4.26                 6.45343
     7          0.16464          29634.29           3.28                 6.47225
     8          0.16468          29602.16           3.41                 9.24667
     9          0.16277          29597.64           2.84                 4.73214
    10          0.16176          29572.86           3.45                 4.35966
    11          0.16176          29572.86           0.00                 4.35966

--------------------------- Pyramid Level = 2 -------------------------------- 
               Normalized     Function local                          Closeness to
 Iteration        rmse            minima          Step-size        optimal solution
     1          0.12139          29164.12           9.06                 7.14654
     2          0.11765          28862.99           5.23                 7.51096
     3          0.11638          28735.95           3.36                 5.13431
     4          0.11604          28645.66           3.50                 6.77245
     5          0.11627          28571.44           4.39                 7.44115
     6          0.11643          28484.52           3.61                 6.90513
     7          0.11650          28430.70           2.00                 4.35053
     8          0.11647          28378.27           2.95                 6.94753
     9          0.11613          28331.36           3.26                 7.69637
    10          0.11584          28303.83           2.11                 6.46119
    11          0.11552          28262.96           2.64                 4.12786
    12          0.11530          28249.84           2.80                11.04359
    13          0.11536          28165.72           3.59                 7.07861
    14          0.11575          28115.74           1.89                 4.88700
    15          0.11620          28076.12           2.02                 7.58377
    16          0.11622          28074.33           0.16                 7.56146

--------------------------- Pyramid Level = 1 -------------------------------- 
               Normalized     Function local                          Closeness to
 Iteration        rmse            minima          Step-size        optimal solution
     1          0.08227          31990.04          11.46                 9.08694
     2          0.08242          31703.92           3.95                 6.42663
     3          0.08259          31673.28           2.83                 5.67244
     4          0.08258          31592.70           1.62                 2.86766
     5          0.08248          31472.07           3.63                 3.94960
     6          0.08236          31394.89           4.08                 8.77333
     7          0.08236          31318.72           3.15                 6.37418
     8          0.08241          31284.28           2.45                 7.80324
     9          0.08246          31261.99           2.13                 5.12845
    10          0.08250          31229.44           2.73                 9.01955
    11          0.08251          31184.45           2.76                 3.64361
    12          0.08250          31134.16           2.36                 4.62543
    13          0.08248          31093.56           2.20                 4.72334
    14          0.08242          31058.02           3.06                 4.89104
    15          0.08241          31054.33           0.65                 4.79401
    16          0.08241          31043.47           4.64                 4.55497
    17          0.08246          30993.97           1.31                 4.77205
    18          0.08250          30974.60           1.80                 2.70111
    19          0.08252          30930.28           3.55                 2.98518
    20          0.08254          30888.53           3.00                 6.74033
    21          0.08255          30859.25           0.88                 3.84308
    22          0.08255          30832.77           0.33                 4.47998
    23          0.08256          30830.20           0.29                 4.08084
    24          0.08256          30822.42           0.76                 3.60578
    25          0.08256          30821.96           0.31                 3.39638
    26          0.08256          30818.17           0.43                 3.08190

Display the fixed image and the registered image. Observe the alignment of the images.

figure
imshowpair(fixed,reg)

Figure contains an axes object. The axes object contains an object of type image.

Load a MAT file containing a reference volume into the workspace. Convert the reference volume to data type double.

load mristack.mat
fixed = im2double(squeeze(mristack));

Create a deformed volume using local transformations.

local = fixed(160:200,100:140,:);
local = imrotate(local,90);
moving = fixed;
moving(160:200,100:140,:) = local;

Display a slice of the fixed volume and a corresponding slice of the moving volume. Observe the deformation in the alignment of the volumes.

figure
imshowpair(fixed(:,:,10),moving(:,:,10))

Figure contains an axes object. The axes object contains an object of type image.

Register the moving volume to the fixed volume.

[dispField,reg]=imregdeform(moving,fixed,GridRegularization=0.001);
--------------------------- Pyramid Level = 3 -------------------------------- 
               Normalized     Function local                          Closeness to
 Iteration        rmse            minima          Step-size        optimal solution
     1          0.00016          34081.23           4.60                79.85176
     2          0.00016          27591.18          16.75                70.06876
     3          0.00019          26948.09          23.68                65.83620
     4          0.00018          26498.21           5.02                59.19717
     5          0.00018          25872.69           8.68                43.63346
     6          0.00019          25774.23           7.70                46.14477
     7          0.00019          25774.23           0.00                46.14477

--------------------------- Pyramid Level = 2 -------------------------------- 
               Normalized     Function local                          Closeness to
 Iteration        rmse            minima          Step-size        optimal solution
     1          0.00009          24832.60           6.00                46.80394
     2          0.00012          24491.93          29.78                58.92927
     3          0.00014          21486.74           9.76                59.40296
     4          0.00010          20100.15           7.82                36.86658
     5          0.00010          19653.02           5.40                32.11689
     6          0.00009          19344.57           6.25                27.88253
     7          0.00009          19179.94           6.32                26.61265
     8          0.00008          19105.13           6.35                25.79584
     9          0.00008          19105.13           0.00                25.79584

--------------------------- Pyramid Level = 1 -------------------------------- 
               Normalized     Function local                          Closeness to
 Iteration        rmse            minima          Step-size        optimal solution
     1          0.00005          22834.26           6.43                25.64158
     2          0.00006          21498.26          20.85                63.44257
     3          0.00007          20173.48          11.87                81.18027
     4          0.00006          20039.11          21.12                51.90494
     5          0.00006          19909.26           3.44                51.33763
     6          0.00005          19738.00           4.92                45.68723
     7          0.00005          19542.03           6.75                37.99851
     8          0.00005          19430.34           7.47                30.56819
     9          0.00005          19396.99           4.20                26.59914

Display the same slice of the fixed volume and the corresponding slice of the registered volume. Observe the improved alignment of the volumes.

figure
imshowpair(fixed(:,:,10),reg(:,:,10))

Figure contains an axes object. The axes object contains an object of type image.

Input Arguments

collapse all

Image or volume to be registered, specified as a 2-D numeric matrix or 3-D numeric array, respectively. The size of moving must be the same as the size of fixed.

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

Reference image or volume, specified as a 2-D numeric matrix or 3-D numeric array, respectively. The size of fixed must be the same as the size of moving.

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

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: [dispField,reg] = imregdeform(moving,fixed,NumPyramidLevels=6) registers moving to fixed using six pyramid levels.

Grid spacing, specified as a two-element or three-element numeric vector.

If moving and fixed are 2-D grayscale images, GridSpacing must be a two-element vector, and its default value is [4 4]. If moving and fixed are 3-D intensity volumes, GridSpacing must be a three-element vector, and its default value is [4 4 4]. Smaller values of GridSpacing specify a finer grid resolution.

Data Types: double

Pixel size, specified as a two-element or three-element numeric vector. Values are in millimeters.

If moving and fixed are 2-D grayscale images, PixelResolution must be a two-element vector, and its default value is [1 1]. If moving and fixed are 3-D intensity volumes, PixelResolution must be a three-element vector, and its default value is [1 1 1].

Data Types: double

Number of multiresolution pyramid levels, specified as a positive integer.

  • If moving and fixed are 2-D grayscale images of size M-by-N, then the value of NumPyramidlevels must satisfy the condition min([M N]) > (2^NumPyramidLevels)*0.7.

  • If moving and fixed are 3-D intensity volumes of size M-by-N-by-P, then the value of NumPyramidlevels must satisfy the condition min([M N P]) > (2^NumPyramidLevels)*0.7.

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

Weighing factor for grid displacement regularization, specified as a nonnegative scalar.

A large value for GridRegularization can create a smooth output displacement field, whereas a small value can create more localized displacements.

Data Types: double

Progress information output, specified as a numeric or logical 1 (true) or 0 (false). Specify DisplayProgress as true to display information such as the number of iterations, normalized root mean square error (RMSE), function local minima, step size, and closeness to optimal solution.

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

Output Arguments

collapse all

Displacement field, returned as a 3-D or 4-D numeric array.

If moving and fixed are 2-D grayscale images of size M-by-N, the displacement field dispField is a 3-D numeric array of size M-by-N-by-2, where dispField(:,:,1) and dispField(:,:,2) contain the displacements in the X- and Y- directions, respectively. If moving and fixed are 3-D intensity volumes of size M-by-N-by-P, the displacement field dispField is a 4-D numeric array of size M-by-N-by-P-by-3, where dispField(:,:,1), dispField(:,:,2), and dispField(:,:,3) contain the displacements in the X-, Y- and Z- directions, respectively.

Data Types: double

Registered image or volume, returned with the same size and data type as moving.

References

[1] Vishnevskiy, Valery, Tobias Gass, Gabor Szekely, Christine Tanner, and Orcun Goksel. “Isotropic Total Variation Regularization of Displacements in Parametric Image Registration.” IEEE Transactions on Medical Imaging 36, no. 2 (February 2017): 385–95. https://doi.org/10.1109/TMI.2016.2610583.

Version History

Introduced in R2022b