BUG: Fix polar angle in MinMaxCurvatureFlowFunction threshold#6603
Merged
hjmjohnson merged 1 commit intoJul 13, 2026
Merged
Conversation
Contributor
|
| Filename | Overview |
|---|---|
| Modules/Filtering/CurvatureFlow/include/itkMinMaxCurvatureFlowFunction.hxx | Normalizes the 3D threshold gradient to unit length before spherical angle calculation. |
| Modules/Filtering/CurvatureFlow/test/CMakeLists.txt | Adds the new CurvatureFlow GoogleTest source list and driver registration. |
| Modules/Filtering/CurvatureFlow/test/itkMinMaxCurvatureFlowFunctionGTest.cxx | Adds a direct regression test for the corrected radius-two 3D update decision. |
Reviews (1): Last reviewed commit: "BUG: Fix polar angle in MinMaxCurvatureF..." | Re-trigger Greptile
The 3-D threshold gradient was rescaled to length StencilRadius before acos(), instead of to unit length. For radius >= 2 this returns the wrong polar angle, misplacing the perpendicular sample points used to pick the min/max curvature update. Addresses item B7 of InsightSoftwareConsortium#6575.
b6a2014 to
2a04261
Compare
hjmjohnson
approved these changes
Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The 3-D min/max threshold rescaled the gradient to length
StencilRadiusand then passed a component of it toacos(), which needs a unit-length cosine. Addresses B7 of #6575.Root cause
MinMaxCurvatureFlowFunction::ComputeThreshold(const Dispatch<3> &, ...)(itkMinMaxCurvatureFlowFunction.hxx:311):After that division each
gradient[k]isr * cos(theta_k), notcos(theta_k). The clamp to[-1, 1]just below hides the domain violation, so no NaN appears — the function silently returns the wrong polar angle. With the defaultStencilRadiusof 2, a truecos(theta) = 0.4(theta = 66.4 deg) is evaluated asacos(0.8) = 36.9 deg, which puts the stencil's perpendicular sample points on the wrong ring and selects the wrong min/max curvature update.Normalizing to unit length is the fix: the downstream position reconstruction already multiplies by
m_StencilRadiusexplicitly. The 2-D dispatch (:246) shares the rescale but reachesatan2on a ratio, where the length cancels — no defect there, left alone.Local validation
New GoogleTest
itkMinMaxCurvatureFlowFunctionGTest.cxx, registered in a newITKCurvatureFlowGTestsdriver.MinMaxCurvatureFlowFunction.ComputeUpdateUsesCorrectPolarAngleAtRadiusTwo— fail-before:result = 1(the buggy angle selects the wrong branch). Pass-after:result = 0. Both values were derived from the test field's geometry before running.ctest -R CurvatureFlow:itkMinMaxCurvatureFlowImageFilterTest,itkBinaryMinMaxCurvatureFlowImageFilterTest,itkCurvatureFlowTestiall pass before and after. They are 100-iteration convergence checks with tolerances, so they do not pin the per-step angle.AI assistance
Historical context for the removed division and the measured downstream impact (SimpleITK baselines) are documented in #6619.