MATLAB Answers

Image Registration Issues - Why is imregister() flipping my moving image upside down?

1 view (last 30 days)
Ashlyn Kapinski
Ashlyn Kapinski on 2 Sep 2020
Answered: Madhav Thakker on 8 Sep 2020
I'm a beginner in MATLAB, trying to align some images using imregister(). The images are of biological tissue sections. I am having some major issues aligning the images... the result from imregister() flips the image entirely upside down, when it shouldn't be.
Why would imregister() flip the moving image upside down like this? The resulting image is now even more mis-aligned to the fixed imaged than it was pre-registration. Also, the tissue sections to be aligned in the fixed and moving images are very similar to begin with so I'm not sure why imregister() would make such a false alignment.
Here is my very basic code:
fixed = imread('slice1.jpg');
moving = imread('slice2.jpg');
gfixed = rgb2gray(fixed);
gfixed2 = medfilt2(gfixed);
img1 = adapthisteq(gfixed2);
gmoving = rgb2gray(moving);
gmoving2 = medfilt2(gmoving);
img2 = adapthisteq(gmoving2);
[optimizer,metric]=imregconfig('monomodal');
optimizer.GradientMagnitudeTolerance = 1.00000e-04;
optimizer.MinimumStepLength = 3.00000e-04;
optimizer.MaximumStepLength = 6.25000e-02;
optimizer.MaximumIterations = 300;
optimizer.RelaxationFactor = 0.500000;
im_aligned = imregister(img2, img1,'rigid',optimizer,metric);
figure(1),imshowpair(img1,im_aligned); % shows im_aligned is entirely flipped upsite down with respect to fixed image
  2 Comments
Ashlyn Kapinski
Ashlyn Kapinski on 3 Sep 2020
My mistake, Matt. Here are the images. I tested this method in a for loop with a stack of several slices... so there are more than these two slices to be aligned and they are all having the same issue (getting flipped upside down or just becoming even worsely misaligned). For ease of the discussion, I didn't include the entire stack of images, but used two that showed what was happening with several.... hopefully I can get some reasonable feedback on why this is generally happening based off of these two images?
Please note that in the above code, I accidentally have my fixed image named as "slice1" and my moving as "slice2". This should be changed to "slice2", and "slice3", respectively, as those are the images I intended to include here.

Sign in to comment.

Answers (1)

Madhav Thakker
Madhav Thakker on 8 Sep 2020
Hi Ashlyn,
I understand that the moving image is flipped after registration. One reason for the flipping can be because of using rigid parameter when calling imregister(). The rigid transformation only supports translation and rotating. It is clear from the images that objects of interest are not of same size in the images. I made a few changes in your code and it seems to be performing better now.
fixed = imread('slice2.jpg');
moving = imread('slice3.jpg');
gfixed = rgb2gray(fixed);
gfixed2 = medfilt2(gfixed);
img1 = adapthisteq(gfixed2);
gmoving = rgb2gray(moving);
gmoving2 = medfilt2(gmoving);
img2 = adapthisteq(gmoving2);
[optimizer,metric]=imregconfig('multimodal');
optimizer.MaximumIterations = 300;
im_aligned = imregister(img2, img1,'similarity',optimizer,metric);
figure(1),imshowpair(img1,im_aligned); % shows im_aligned is entirely flipped upsite down with respect to fixed image
Hope this helps.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!