Transformation matrix (projective2d) change of origin at application

I have a transformation matrix (as a projective2d object) created with fitgeotrans(), which should be used as an image correction, and a simulated image, which I want to use for validation of this transformation matrix.
The points used as input for fitgeotrans() are calculated before based on some measurements, which works fine.
I apply the transformation matrix via the imwarp() function onto the simulated image. But now it seems that the correction is applied with the origin at the wrong point.
How can I change that, if the points used as input for the fitgeotrans() are assumed to be correct? And I do not think that the transformation matrix changes if I change the input order of the points in fitgeotrans(). (As long as the fixedpoints and their corresponding movingpoints are at the same position.)
Edit (30.11.2021): After some additional research, I have the suspicion, that i should maybe ask the question differently: How can I apply the transformation matrix so that the origin on the matrix is in the center before and after correction?
Any help is appreciated.

1 Comment

I think what I will try, is to calculate the translation, where the origin is now vs where the origin should be. Then translate the input points of fitgeotrans() and then calculate the transformation matrix.

Sign in to comment.

Answers (1)

Matt J
Matt J on 30 Nov 2021
Edited: Matt J on 30 Nov 2021
You should use imwarp's OutputView option to specify a coordinate system for the output with the origin in the center.

8 Comments

I saw the displacement field parameter in imwarp(), but I will have a look on the OutputView. Thankyou very much!
Since my transformation is not an affine, but a projective one, I would use imref2d().
So the code should look like this(?):
pixelExtendInWorldX=410; %I know that the image plane in real world is 410x410 mm big.
pixelExtendInWorldY=410;
outputimref2d=imref2d(size(originalimage), pixelExtendInWorldX, pixelExtentInWorldY);
imagecorr=imwarp(originalimage, tform, 'OutputView', outputimref2d);
Edit: I tried these lines and they liead to the result that the 'corrected image' is in the top left corner and really small. But somehow I think that this leads in a direction, or maybe it is just hope.
You need to use this syntax of imref2d()
outputimref2d=imref2d(size(originalimage) ,xWorldLimits,yWorldLimits)
where xWorldLimits,yWorldLimits would be chosen so that the new origin is in the center of the image grid.
I just realised that I screwed up the pixelExtendInWorld parameters. As I corrected that, the result is more the desired shape, but cut off.
First, thank you for the fast comment.
Do I understand it correctly, that the xWorldLimits and yWorldLimits are the boundaries I have from the real world coordinate system I used to calculate the transformation matrix? I will definetly try that!
Edit: No, I must have misunderstood something, because the rectangular shape which should be in the middle of the iamge is all over the left part of the image (with a right corner at the bottom).
Yes, it specifies the section of real world coordinate space that you want to see in the output.
Thank you! So my thought is correct, just the execution somehow wrong. I have to think about that.
I git quite far with this!
However, I still do not get the desired result. But this comment or question was too long, so I wrote a new question about it.
But this comment or question was too long
Why?

Sign in to comment.

Products

Release

R2019b

Asked:

on 29 Nov 2021

Commented:

on 5 Dec 2021

Community Treasure Hunt

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

Start Hunting!