Resizing displacement field from imregdemons does not yield accurate transformation

7 views (last 30 days)
Greetings,
I'm trying to register two images (m = moving image to be transformed, s = static reference image) by estimating a displacement field (d) required to map pixels on 'm' to 's'. 'm' and 's' were originally downsampled images, as I couldn't calculate 'd' without getting an OutOfMemory error (done on a GPUarray). My goal was to use imregdemons to calculate 'd' on downsampled versions of 'm' and 's', then use imresize to rescale 'd' to match the size of the original images (accepting the slight loss in accuracy of the alignment). Finally, I would use imwarp to apply the enlarged displacement field on the full size images to get a transformed image.
However, the transformed image calculated from the enlarged 'd' appears drastically different from the transformed image at the original scale. I expected there to be some loss in registration accuracy due to calculating it on a downsampled array, however I suspect that there is either an issue with how I've rescaled it or how I've applied the transform. See below for the code, and here for the files used in the example.
Thanks for taking the time to read this, regardless if you're able to provide assistance.
clear
close all
%% Load images, specify imregdemon parameters
m=gpuArray(imread('test_moving.tif'));
s=gpuArray(imread('test_static.tif'));
m=imadjust(m);
s=imadjust(s);
iterations=100;
smoothing=3;
pyramid=8;
%% Calculate displacement field on normal-sized images
[d,~] = imregdemons(m,s,iterations,'AccumulatedFieldSmoothing',smoothing,'PyramidLevels',pyramid);
[moved, ~] = imwarp(gather(m), gather(d));
imshow(cat(3,moved,s,s))
title('Displacement field calculated and applied on original-scale images')
%% Resize static, moving, and displacement field arrays
m_large=imresize(gather(m),2);
s_large=imresize(gather(s),2);
d_large=imresize(gather(d),2);
moved_large=imwarp(m_large,d_large);
figure;
imshow(cat(3,moved_large,s_large,s_large))
title('Transformed image relative to static after upscaling static,moving, and displacement field arrays')
figure;
imshow(imresize(cat(3,moved_large,s_large,s_large),1/2))
title('upscaled images resized to original size. In theory, they should be identical to the first figure +/- 2 pixels on x and y')

Accepted Answer

Syed Mark Zaidi
Syed Mark Zaidi on 18 Feb 2020
Turns out, in addition to resizing the displacement field, the magnitude of the elements must also be "resized", in that they need to be multiplied by the scale factor (in this case, multiply each element in the displacement field array by 2).

More Answers (0)

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!