Manually written tform (images.ge​otrans.Pol​ynomialTra​nsformatio​n2D) does not work in right way.

3 vues (au cours des 30 derniers jours)
I am correcting a chromatic errror from two images by using polynomial fitting.
The images have many spot pairs and I could get the images.geotrans.PolynomialTransformation2D object and correct the second image like below.
tform = fitgeotrans(movingPoints,fixedPoints,'polynomial',2);
Jregistered = imwarp(J,tform,'OutputView',imref2d(size(I)));
figure
subplot(1,2,1)
imshowpair(I,J,'falsecolor')
title('compare I & J');
subplot(1,2,2)
imshowpair(I,Jregistered,'falsecolor');
title('after imwarp');
imwrap1.png
I want to make the tform (images.geotrans.PolynomialTransformation2D) with known coefficients and repeat this procedure.
I made one reusing the coefficients from fitgeotrans, but it makes totally different images.
tform_new = images.geotrans.PolynomialTransformation2D(tform.A,tform.B) ;
J_new= imwarp(J,imref2d(size(J)),tform_new,'OutputView',imref2d(size(I)));
figure
subplot(1,2,1)
imshowpair(I,J,'falsecolor')
title('compare I & J');
subplot(1,2,2)
imshowpair(I,J_new,'falsecolor');
title('after imwarp');
imwrap2.png
The 'tform' and 'tform_new' are exactly same as shown in worksapce.
I do not understand what makes this difference. I need to edit the coefficients.
Is there any hidden parameter or property in 'images.geotrans.PolynomialTransformation2D' I need to change?

Réponses (1)

RogerWilco
RogerWilco le 21 Fév 2024
Modifié(e) : RogerWilco le 21 Fév 2024
Just take into account the coefficient isn't enough to get an exact copy of the transform.
Eventhough the coefficients are the same:
>> isequal(tform.A, tform_new.A)
ans =
logical
1
>> isequal(tform.B, tform_new.B)
ans =
logical
1
The transformations aren't:
>> isequal(tform, tform_new)
ans =
logical
0
In addition to the coefficients PolynomialTransformation2D uses the private properties normTransformXY and normTransformUV, which you can't see/access directly. These aren't set when generating the transformation just by coefficients.
But you can use the hidden methods saveobj and loadobj to rebuild the transformation like:
tformStruct = tform.saveobj;
tform_new = images.geotrans.PolynomialTransformation2D.loadobj(tformStruct);
Now, the transformations are the same:
>> isequal(tform, tform_new)
ans =
logical
1
Hope, this still helps.
Cheers,
Ralf
  2 commentaires
Myunghyun
Myunghyun le 21 Fév 2024
Sorry, I cannot accept the answer because I lost the access for MATLAB account I had in the former institute...

Connectez-vous pour commenter.

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by