# how can I use imregister() about the center of an image

6 views (last 30 days)
Dan on 16 Aug 2014
Commented: Matt J on 19 Aug 2014
Straight to the point : Can anyone tell me 1) How I can convert the transformation matrix about the top left corner to the transformation about the center pixel? I assume this is some simple linear algebra ? or better yet. 2) How to use imregister() about the center pixel of the moving and fixed image?
This is why I am interested: I want to be able to apply a transformation onto a picture about its center , then use imregister to match it with the original picture and find out what imregister thinks the transformation that I applied was.
What I have done:
*I relied on this paper ( pages 6 and 7 has some relevant equations ).
1) I decided on transformation parameters ( translation in xy, rotation ccw, shear, and scale in xy). Then I made a transformation matrix from it based on the work of the reference above. 1)I took the original picture , translated it to the picture to the center pixel , applied the transformation , then applied an inverse of the translation matrix onto it. (ie inv(trans)*Transformaton*trans = newTransform.
2)I ran imregister with moving = transformed picture , fixed = original picture , standard optimization and metric parameters.
3)I extracted the tform.T martix that imregtransform() finds ( inside of imregister ).
4) I used the following reference above calculations to break down the transformation matrix into the parameters of the imregister transformation ( rotation, shear...etc)
5) I compared the inverse of the transformation I originally applied and the transformation that imregister found ... and they are not at all similar.
I made a similar program that did all the transformations about the top left corner and then imregister had no problem finding the right numbers...
I also tried to shift the moving and fixed pictures so that the center pixel is at the origin and run imregister. This also did not work.

Matt J on 16 Aug 2014
Edited: Matt J on 16 Aug 2014
How I can convert the transformation matrix about the top left corner to the transformation about the center pixel?
If you have an affine transformation
y=A*x+t
where A is a nxn linear transformation matrix and t a nx1 translation vector, you can express the transformation with respect to a different origin z by rewriting the above in the following equivalent form
y-z= A*(x-z) + A*z-z + t
Now, define
ynew=y-z
xnew=x-z
tnew= A*z-z + t
and this becomes
ynew=A*xnew+tnew
But note that xnew and ynew are the same as x and y but expressed relative to a new origin, z.
2) How to use imregister() about the center pixel of the moving and fixed image?
You can specify the location of the world coordinate origin in each image using the 2nd syntax of imregister mentioned in the documentation
[moving_reg,R_reg]= imregister(moving,Rmoving,fixed,Rfixed,transformType,optimizer,metric)
In particular Rmoving and Rfixed are created with imref2d (or imref3d) to define the relationship between the coordinates of the two images with world coordinates.
Matt J on 19 Aug 2014
Dan commented:
Thank you very much - that was exactly what I needed.