Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Similarity3DTransform API #4149

Open
lvora opened this issue Aug 8, 2023 · 9 comments
Open

Similarity3DTransform API #4149

lvora opened this issue Aug 8, 2023 · 9 comments
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances

Comments

@lvora
Copy link

lvora commented Aug 8, 2023

We have noticed that the similarity3DTransform API returns a reflection along with the scale factor (negative scale factor). Both GetMatrix() as well as the GetFixedParameters() API return the reflection. We are just using the standard ITK code
The reflection is unexpected since the doc seems to indicate that the transformation model has translation, rotation and scaling but no reflection. Can you tell us if this is a bug?
https://itk.org/Doxygen/html/classitk_1_1Similarity3DTransform.html

@lvora lvora added the type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances label Aug 8, 2023
@github-actions
Copy link

github-actions bot commented Aug 8, 2023

Thank you for contributing an issue! 🙏

Welcome to the ITK community! 🤗👋☀️

We are glad you are here and appreciate your contribution. Please keep in mind our community participation guidelines. 📜
Also, please check existing open issues and consider discussion on the ITK Discourse. 📖

This is an automatic message. Allow for time for the ITK community to be able to read the issue and comment on it.

@dzenanz
Copy link
Member

dzenanz commented Aug 8, 2023

Please provide a minimal reproduction example.

@lvora
Copy link
Author

lvora commented Aug 8, 2023

While we are seeking permission to use customer data to provide a reproduction procedure, can you confirm whether or not this API is intended to return a similarity transformation with no reflection?

@dzenanz
Copy link
Member

dzenanz commented Aug 8, 2023

There is only a single scaling factor, but I am not sure whether there is any effort to constrain it to positive values, by e.g. registration optimizers. Of course, this factor was definitely imagined to be positive.

@gdevenyi
Copy link
Contributor

gdevenyi commented Aug 8, 2023

The reflection is unexpected since the doc seems to indicate that the transformation model has translation, reflection and scaling but no rotation. Can you tell us if this is a bug?

To clarify, this is what the transformation says it has:

The serialization of the optimizable parameters is an array of 7 elements. The first 3 elements are the components of the versor representation of 3D rotation. The next 3 parameters defines the translation in each dimension. The last parameter defines the isotropic scaling.

@ataylor-mw
Copy link

ataylor-mw commented Aug 10, 2023

Thanks @gdevenyi and @dzenanz . I agree with that the optimizer in registration seems to be allowed to explore negative portions of parameter space for scale, which is not what we want to allow or would have expected when using the Similarity3DTransform. I am not able to share the data we have in which the registration returns a Similarity3DTransform that includes reflection.

I note that in SimpleITK, the following construction with a negative scale factor succeeds and returns an output from GetMatrix that is not a rotation matrix (negative determinant), and reports an output from GetScale which is negative:

import SimpleITK as sitk

rotation_center = (0, 0, 0)
axis = (0,0,1)
angle = 0.0
translation = (0.0,0.0,0.0)
scale_factor = -1.0
similarity = sitk.Similarity3DTransform(scale_factor, axis, angle, translation, rotation_center)

print("Scale: "+str(similarity.GetScale()))
print("Matrix: "+str(similarity.GetMatrix()))

The output of this is:

Scale: -1.0
Matrix: (-1.0, -0.0, -0.0, -0.0, -1.0, -0.0, -0.0, -0.0, -1.0)

My questions are:

  1. Can you clarify what it means that Scale is "imagined to be positive" in light of the fact that you can get/set the object into a negative scale state directly? Is this a bug in ITK or intentional behavior in the transformation model as a desired degree of freedom? I personally find it unexpected that the Similarity3DTransform allows you to query its Scale and is allowed to report Scale as a negative quantity. I feel similarly about the doc discussing "isotropic scale". I don't think a plain read of "isotropic scale" would include an expectation of negative values/reflection in most people's mental model.

  2. Is there a way in ITK to define a registration scheme such that the search space is constrained to be strictly the non-reflective subset of similarity transformation? I only want the optimizer to be able to consider positive scale factors in parameter space. Is there a way to do that? That might include a different transformation object or some mechanism in the registration algorithm side for constraining search space, or something else I haven't considered.

@dzenanz
Copy link
Member

dzenanz commented Aug 10, 2023

  1. You and I are in agreement, that neither of us expects negative scales. That's what I meant by "imagined to be positive".
  2. You could use an optimizer which supports bounds, such as LBFGSB.

If you think the situation could be improved, we are always open to accepting contributions (preferably in the form of PRs).

@gdevenyi
Copy link
Contributor

You could use an optimizer which supports bounds, such as LBFGSB.

One other thing to ensure optimization meets expectations is to ensure initialization is done properly, and that the similarity metric is properly conditioned to push the optimization in the "correct" direction. The optimizer tries to improve the metric and if that happens to include pushing scaling to the negative direction then it will happen (subject to optimizers with boundaries)

@seddins
Copy link

seddins commented Aug 31, 2023

Thank you for the suggestions that you have made:

  1. Use an optimizer that supports bounds
  2. Supply a different initial condition
  3. Condition the similarity metric to push the solution towards positive scale factors
  4. Propose a change to ITK in the form of a pull request

We might be able to provide 1 as an option to our users in a future product release, and we might be able to suggest 2 to users when a negative scale factor is encountered. We can also explore 3. We don’t have the resources at the moment to investigate 4.

I would like to suggest, for your future consideration, that a parameterization of scale + rotation + translation is not ideal for similarity transformations if the scale is allowed to be negative.

In 3-D, a negative scale factor results in an opposite similarity, one that reverses object orientations. We have customers for whom such a transformation is not physically realizable in the systems they are modeling.

On the other hand, if one does wish to allow opposite similarities, the parameterization is still not ideal because it can’t represent an opposite similarity at all in 2-D, and it can’t represent all types of opposite similarities in 3-D.

For the case where one doesn’t want an opposite similarity, I’m not aware of an unbounded parameterization that would be suitable, but perhaps one does exist.

For the case where one wants to allow opposite similarities, an unbounded parameterization that covers all the reflection cases in both 2-D and 3-D would be a scale factor (positive or negative), an orthogonal matrix (not restricted to rotations), and a translation.

Thanks again for your suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances
Projects
None yet
Development

No branches or pull requests

5 participants