-
-
Notifications
You must be signed in to change notification settings - Fork 686
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
Fixed parameter preservation after identity #4485
Fixed parameter preservation after identity #4485
Conversation
Modules/Core/Transform/include/itkMatrixOffsetTransformBase.hxx
Outdated
Show resolved
Hide resolved
96270fb
to
f427be5
Compare
Just for my understanding: how is that with transform types which (may not be not derived from MatrixOffsetTransformBase)? Do (or should) they always preserve the fixed parameters, whenever |
Modules/Core/Transform/include/itkMatrixOffsetTransformBase.hxx
Outdated
Show resolved
Hide resolved
f427be5
to
981c53a
Compare
@N-Dekker FixedParameters should never change after being chosen, they represent the static component of the structure of the transform. Similar to template parameters for a function in C++. the "Parameters" represent the current state of the Transform (i.e. Not the structure of the transform). The SetIdentity() function should change the state of the transform, not the structure of the transform. Consider a displacement field transform. The "Parameters" are the vector values of the underlying image. The "FixedParameters" are the Size/Origin/Spacing/Direction components that define the underlying vector image. Setting the displacement field to an identity involves setting the vector values to all zeros, and should not modify the Size/Origin/Spacing/Direction elements of the underlying vector image. |
Thanks for your clear explanation, @hjmjohnson Unfortunately I think my knowledge and understanding of
BTW, I won't stop this PR, I'm just trying to understand, because it seems a bit tricky to me! |
Could you possibly still explain where in the original ITK/Modules/Core/Transform/include/itkMatrixOffsetTransformBase.hxx Lines 96 to 107 in 13ccff6
|
@N-Dekker The problem (at least for the Euler3DTransform) is explicitly that the m_Center is being filled with all zeros. Initially I tried removing filling the center with all zeros, but that caused a family of "Scale*Transforms" to start failing regression tests. The issue, I think, is that the behavior of the m_Center and m_Offset parameters can be manipulated by "SetFixedParameters" of the child classes. My solution works under the principle that transforms can be properly configured with only "SetParamters" and "SetFixedParameters" from the child classes (as is done in the TransformIO mechansims). Under this known behavior of all transforms, I concluded that restoring the fixed parameters would set the state of the class correct for whatever weird behavior a child class may choose to do. Well. ...... that was my rational for this approach which a) Passes all regression tests, and b) fixes the nasty conceptual bug I ran into when using the Eurler3DTransform with SetIdentity. |
Thanks again Hans. I just did a rebuild of the latest master branch, having locally removed the questionable m_Center zero-filling:
I'll try the tests in a moment... Update: as far as I can see, the Scale*Transform tests are passing successfully on my PC (VS2019 Debug), after having locally removed the
Which specific regression failures did you get? Do you think they were major failures, or possibly just rounding errors? |
981c53a
to
8453403
Compare
m_Center.Fill(InputPointValueType{}); | ||
// Fixed parameters must be preserved when setting the transform to identity | ||
// the center is part of the stationary fixed parameters | ||
// and should not be modified by SetIdentity. m_Center.Fill(InputPointValueType{}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much for giving this approach a try, Hans! I think it's the right way to go. As far as I can see, the Scale*Transform tests still pass 👍 (Right? Please check!) Only itkSimilarity2DTransformTest appears to fail, but I think itkSimilarity2DTransformTest itself is wrong! I'll have another look.
I see, itkSimilarity2DTransformTest assumes that transform->SetIdentity()
also resets the center. If we agree that that assumption should be dropped (the main purpose of your PR), the test should just manually reset the center. Specifically here, around line 159:
ITK/Modules/Core/Transform/test/itkSimilarity2DTransformTest.cxx
Lines 158 to 159 in cd49925
// 15 degrees in radians | |
transform->SetIdentity(); |
The test fails because it tries to do the 15 degrees rotations from the wrong center. It will pass when a transform->SetCenter({})
is added, either before or after transform->SetIdentity()
.
Hope that helps!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@N-Dekker Thanks. I won't be able to spend time digging into this until after next week. I appreciate any assistance I can get.
2877 - itkSimilarity2DTransformTest (Failed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, just adding transform->SetCenter({})
to line 159 of itkSimilarity2DTransformTest.cxx should make the CI happy.
Conceptually, people should no longer assume that transform->SetIdentity()
"automagically" resets the center. It's a (potentially) breaking change. But I think it's a correct one.
When setting a transform to represent an Identity mapping, it is crucial that the stationary component of the transform is preserved. ```python tfm.SetCenter( [1,2,3] ); tfm.SetIdentity(); out=tfm.GetCenter(); assert( out == [1,2,3] ); ``` =============== Add test demonstrating change in fixed paramers When applying SetIdentity(), the fixed parameters should not be modified. The fixed paramers represent the stationary component of the transform and setting the transform back to an identity should not modify the stationary components.
8453403
to
0ccf872
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much, Hans! 👍
I think this PR is ready for merge, but I would like to see one more approval! Especially because there is a tiny little chance that some user may experience slightly different behavior, because with this PR, |
db9cfea
into
InsightSoftwareConsortium:master
When setting a transform to represent an Identity mapping, it is crucial that the stationary component of the transform is preserved.
PR Checklist
files (if any)