How does imregtform work?

11 views (last 30 days)
Hello! I'm trying to register two images taken with an endoscope. When I run this piece of code, Matlab gets stuck in the imregtfrom function and I have to end the program manually. This is what my code looks like:
fixed = rgb2gray(imread('test1.jpg'));
moving = rgb2gray(imread('test2.jpg'));
imshowpair(fixed, moving,'Scaling','joint')
optimizer = registration.optimizer.OnePlusOneEvolutionary;
metric = registration.metric.MattesMutualInformation
optimizer.InitialRadius = 0.009;
optimizer.Epsilon = 1.5e-4;
optimizer.GrowthFactor = 1.01;
optimizer.MaximumIterations = 300;
movingRegistered = imregister(moving,fixed,'affine',optimizer,metric);
figure
imshowpair(fixed, movingRegistered,'Scaling','joint')
When I end the run session, I get these messages in the command window:
I'm not sure where my mistake is, I am trying to do something similar to the example on this page. Thank you!
  2 Comments
Matt J
Matt J on 5 Sep 2022
I suggest attaching test1.png and test2.ng so that we can try ourselves.
Manasvini
Manasvini on 5 Sep 2022
The photos are attatched here, they are dental images taken with an endoscope. Thank you!

Sign in to comment.

Accepted Answer

Chaitanya Krishna Kantambhatla
Thanks for sharing the image files.
I could execute the code that you shared, and the code runs with out any error. However, it is taking a long time to get the results. (It took 437.251294 sec on my end).
There are a few approaches that you may wish to explore when increasing your performance of the 'imregister' function. Please find a brief summary of the possible approaches below:
1) As 'imregister' uses an iterative algorithm, it's performance will linearly scale with the number of iterations. You may wish to try to manually tune the 'MaximumIterations' property of the optimizer object returned by 'imregconfig' to determine if you can obtain an acceptable registration in fewer iterations.
2) As the image registration is computed with an optimization approach, registration will always be quicker if you can provide a good initial condition for the registration estimate. The closer this initial condition is to the correct alignment, the faster 'imregister' will converge.
3) You may wish to use the 'registrationEstimator' app in MATLAB if you have not already, as this application can help define a registration pipeline that may be able to achieve a good registration and alignment in less time than using 'imregister' alone. Please find a link to the documentation page for this application below:
  3 Comments
Matt J
Matt J on 8 Sep 2022
Edited: Matt J on 8 Sep 2022
(I need my final image to be grayscale)
Use im2gray, or similar.
I reduced the 'MaximumIterations' property and was able to get a registered image much faster.
It should also help to crop your images to a smaller bounding box around the teeth. All the surrounding black pixels are just increasing the required computations and don't really contribute any information to the registration.
.
Manasvini
Manasvini on 9 Sep 2022
Thank you for the cropping advice! I tried doing that and my runtime was much quicker. I don't think using im2gray will work for my project because I will be creating a heatmap from the registered image. Thus, if the Registration Estimator App adds a color overlay and then I convert the image to grayscale, I'll end up with an inaccurate heatmap.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!