InsightSoftwareConsortium / InsightSoftwareConsortium/ITK

Rework the histogram max/min value autocompute flag in the `Thresholding` module

Open
#1,739 3 comments 0 reactions 0 assignees View on GitHub
area:Filtering status:Use_Milestone_Backlog type:Design
Dominant language
C++
Stars
1.7k
Forks
748
Avg merge
1d 1h
Merged PRs (30d)
64

Description

### Description

Decide if the flag allowing to compute and set the histogram maximum and minimum values in the `Thresholding` module filters should be exposed.

The current design does not allow to set or control the range of interest of the histogram if the minimum and maximum values are not allowed to be computed automatically. Hence, when setting it to `false`, the thresholded images not be meaningful.

### Impact Analysis

Allowing to set the histogram maximum and minimum values in the `Thresholding` module filter may involve a non-negligible amount of refactoring and work.

Although this would make the module more consistent with the presence of the `m_AutoMinimumMaximum` flag, leaving outside part of the histogram values **translates this into a non-binary thresholding or classification problem**. Hence, the thresholding modules may need additional refactoring to use ITK classes that are able to label accordingly images.

### Expected behavior

Get meaningful, controllable results when the `itk::HistogramThresholdImageFilter::m_AutoMinimumMaximum` flag is set to `false` for the `Thresholding` filters.

One way to solve this would be able to set the `itk::Statistics::ImageToHistogramFilter`'s `m_Maximum` and `m_Minimum` values manually, and be able to set such an appropriate instance to the `Thresholding` filter (possibly to their histogram calculator member). It should be automatically ensured that those maximum and minimum values are within the dynamic range of the input image.

This involves some sort of logic for the cases where `m_AutoMinimumMaximum` is set to `false`, or some new logic that would remove that flag to set those values by default by the histogram calculator (e.g. the `m_AutoMinimumMaximum = true` case) or set them to values specified by the user. And it may also involve modifying the `itk::ImageToHistogramFilter` API.

This would involve creating an `itk::Statistics::ImageToHistogramFilter` histogram generator instance, e.g. Look

```
if (!autoMinimumMaximum)
{
using HistogramGeneratorType = itk::Statistics::ImageToHistogramFilter;
typename HistogramGeneratorType::Pointer histogramGenerator = HistogramGeneratorType::New();

// Set the maximum and minimum values to desired values
(...)

// Set the histogram generator instance to the thresholding filter
(...)
}
```

The `itk::Statistics::ImageToHistogramFilter::InitializeOutputHistogram` method and the classes involved need to be carefully looked at.

### Actual behavior

The produced generated output is not meaningful because when the `itk::HistogramThresholdImageFilter::m_AutoMinimumMaximum` flag is set to `false`, the `itk::Statistics::ImageToHistogramFilter` does not initialize its `m_Maximum` and `m_Minimum` values to meaningful values, and thus the result of the thresholding process is not meaningful:

1. Run any of the [tests](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Filtering/Thresholding/test/CMakeLists.txt) in the `Thresholding` module where the `autoMinimumMaximum` flag is set to `false`,
e.g. `itkMaximumEntropyThresholdImageFilterTestNoAutoMinMax`)
2. Check that produced output image is not meaningful (i.e. no anatomical structure can be distinguished).
3. Check that the expected threshold value is close to the lower end of the dynamic range of the input image pixels (it is only close due to the histogram's binning effect). In this case, the concerned thresholding filters return the same threshold value (provided that the input image is the same), e.g. `-31744` for `cthead1.png`.

### Versions

`master`

### Additional Information

See [this comment](https://github.com/InsightSoftwareConsortium/ITK/pull/511#issuecomment-605536928) and the context in PR #511.

Related to issues #1737, #1738.

@richardbeare your thoughts and insight is highly appreciated.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.