InsightSoftwareConsortium / ITK

Insight Toolkit (ITK) -- Official Repository. ITK builds on a proven, spatially-oriented architecture for processing, segmentation, and registration of scientific images in two, three, or more dimensions.
https://itk.org
Apache License 2.0
1.42k stars 664 forks source link

Improve description of itkFastMarchingImageFilter exception: Discriminant of quadratic equation is negative #715

Open romangrothausmann opened 5 years ago

romangrothausmann commented 5 years ago

Description

itkFastMarchingImageFilter is called when executing itkSpeedFunctionToPathFilter. Under some circumstances itkFastMarchingImageFilter issues an exception with the description: Discriminant of quadratic equation is negative https://github.com/InsightSoftwareConsortium/ITK/blob/bd8169b433679930c8acfe0e24c8b5a5c663a833/Modules/Filtering/FastMarching/include/itkFastMarchingImageFilter.hxx#L498 However it is not obvious what the reason is that causes this problem. It is unclear when this condition is reached and how to avoid it (and if it depends on itkSpeedFunctionToPathFilter).

Impact analysis

It is good to have an error thrown and a description of the actual problem, as is the current case, but it would be good to have more details on why this happened and possibly how to avoid it.

Expected behavior

err.SetDescription("Discriminant of quadratic equation is negative. This happens when ... and can possibly be avoided by ...");

Actual behavior

I'm hitting this problem with one of my ITK-CLIs here: https://github.com/romangrothausmann/ITK-CLIs/blob/e883088ebf6b19cf945ac01dec1ce81878f8c181/min-path_seg.cxx#L285-L291

It seems to be very input data dependent. The speed function that lead to this error is constructed by the sigmoid of a fast-marching map run inside a binary segmentation starting from the centerlines extracted by itkBinaryThinningImageFilter3D. When using e.g. ParabolicOpenImageFilter on the binary segmentation (as built in) this error does not arise for otherwise same parameters.

Versions

Tested with ITK-4.13.1

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

romangrothausmann commented 5 years ago

I think this is still relevant and it is not clear to me when this happens. @richardbeare Do you have an idea when this can happen?

richardbeare commented 5 years ago

I suspect it occurs when the speed function doesn't conform to the range rules (0-1).

romangrothausmann commented 5 years ago

Hm, oddly I did get this exception even with the min-path_seg CLI where a RescaleIntensityImageFilter makes sure that the rane is within [0, 1]: https://github.com/romangrothausmann/ITK-CLIs/blob/ee05ceb349fe012bff89718f46786bf847877975/min-path_seg.cxx#L165-L169 Are there cases where the RescaleIntensityImageFilter is not sufficiently precise such that values outside [0, 1] ought to be expected?

richardbeare commented 5 years ago

Perhaps some issue with scaling of time step size when the voxels are small? I'm guessing as I don't know the fast marching internals. A test might be to reset voxel sizes of the problem images and see if the error disappears.

romangrothausmann commented 5 years ago

A test might be to reset voxel sizes of the problem images and see if the error disappears.

Yes, this might be the problem, will test this.

thewtex commented 4 years ago

The speed function that lead to this error is constructed by the sigmoid of a fast-marching map run inside a binary segmentation starting from the centerlines extracted by itkBinaryThinningImageFilter3D.

@romangrothausmann out of curiosity, what does this look like?

romangrothausmann commented 4 years ago

I haven't got a 2D exmple ready, but basically it is a speed image whose profile perpendicular to the centerlines resembles a (cropped) sigmoid independent of the local extent of the orginal structure of the binary segmentation.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.

romangrothausmann commented 4 years ago

Related but not limited to: https://github.com/InsightSoftwareConsortium/ITKMinimalPathExtraction/issues/61 https://github.com/InsightSoftwareConsortium/ITKMinimalPathExtraction/pull/71

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.