I want to use cv2.estimateAffinePartial2D without scaling factor

github path of estimateAffinePartial2D is in “opencv/modules/calib3d/src/ptsetreg.cpp”

i want to use cv2.estimateAffinePartial2D without estimating scaling factor.

as you know, estimateAffinePartial2D 's matrix is
image

i know that ‘s’ means scaling factor,
so i decide to change ‘s’ to ‘1’ during estimating affine matrix

but i don’t have any idea how to change estimateAffinePartial2D 's factor

Can you provide more details on what you are trying to achieve - some description about the actual problem you are trying to solve?

Note that cos^2 + sin^2 = 1. If you sum the squares of the elements of the first column (for example), you would get s^2, so taking the square root would give you the scale factor s. You could divide the elements of the 2x2 rotation matrix by s to take out the scale factor. I would think your translation would need to be adjusted, too?

1 Like

and that’s the heart of the matter.

the underlying optimization could be doing that, if OpenCV had the APIs to let you declare which degrees of freedom to optimize for.

if the existing APIs can’t deliver that, I see two options:

  • request this feature
  • do your own optimization from primitives

the APIs are a mess. there is this estimateAffinePartial2D but also estimateAffine2D and neither allow you to lock down arbitrary degrees of freedom. they’re just two or three choices selected from the options.

1 Like

Thank you for answering even though the translation is not good.

I want to do ‘registration’ two tissue stained images by adjusting only the rotation and translation.
The reason why I don’t adjust the scaling is because I don’t want to change the original size of the two images.

I understood that dividing ‘s’ by the matrix was to isolate the scaling.
but I have a new question.
a) If only the ‘s’ is isolated after the affine matrix is estimated
b) If only the scaling factor is excluded during the affine estimation process.

is there a subtle numerical difference in the results between the two(a,b)?
or same results?

I encountered the same problem. There is only rotation and translation in my problem. I find it a little hard to change the source code of opencv and compile it.

Luckily, I find “skimage.transform.estimate_transform()” this function can meet my needs.

When set ttype=“euclidean”, there is only roration and translation.

However, there is no RANSAC in this function.

Reference:
https://scikit-image.org/docs/stable/api/skimage.transform.html#skimage.transform.estimate_transform