How does imregtform work?
9 views (last 30 days)
Show older comments
Manasvini
on 5 Sep 2022
Commented: Manasvini
on 9 Sep 2022
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
Accepted Answer
Chaitanya Krishna Kantambhatla
on 8 Sep 2022
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
on 8 Sep 2022
Edited: Matt J
on 8 Sep 2022
(I need my final image to be grayscale)
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.
.
More Answers (0)
See Also
Categories
Find more on Geometric Transformation and Image Registration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!