InsightSoftwareConsortium / InsightSoftwareConsortium/ITK
ENH: Refactor FastGrowCut to use standard ITK iterators and the filtering pipeline
- Dominant language
- C++
- Stars
- 1.7k
- Forks
- 748
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 64
Description
`FastGrowCut` (ingested in #6274) walks its volumes with hand-rolled 3-D indexing over raw `GetBufferPointer()` and manual region handling instead of standard ITK iterators and pipeline semantics. @dzenanz flagged this during the #6274 review and explicitly deferred it as post-ingestion work; filing so the deferral is not lost.
Reviewer context
- PR: https://github.com/InsightSoftwareConsortium/ITK/pull/6274 — "ENH: Ingest ITKGrowCut into Modules/Segmentation/GrowCut" (merged 2026-05-19).
- Comment: https://github.com/InsightSoftwareConsortium/ITK/pull/6274#issuecomment-4489139204 — @dzenanz: the algorithm is "needlessly complicated by hand-rolled 3D iterators and manual handling of regions"; it should use standard ITK iterators and the ITK filtering pipeline. Explicitly **not** a merge blocker for #6274.
Verified evidence in current main
`Modules/Segmentation/GrowCut/include/itkFastGrowCut.hxx` (425 lines) contains no `ImageRegionIterator` or `NeighborhoodIterator` uses at all. It operates on raw buffer pointers obtained at:
- L71 `seedLabelVolume->GetBufferPointer()`
- L80–81 `resultLabelVolume->GetBufferPointer()`, `m_DistanceVolume->GetBufferPointer()`
- L158 `maskLabelVolume->GetBufferPointer()`
- L195–196, L246–247, L252, L285 — same pattern
Region handling is likewise manual; L344–348 rejects any `RequestedRegion != LargestPossibleRegion` outright:
```
// currently, RequestedRegion is controlled via maskInput
if (region != inRegion)
{
itkExceptionMacro("Currently, RequestedRegion has to be equal to LargestPossibleRegion");
}
```
Affected files:
- `Modules/Segmentation/GrowCut/include/itkFastGrowCut.h`
- `Modules/Segmentation/GrowCut/include/itkFastGrowCut.hxx`
- `Modules/Segmentation/GrowCut/include/FibHeap.h` + `src/FibHeap.cxx` (318-line hand-rolled Fibonacci heap; evaluate replacing with a `std::`/ITK equivalent)
Suggested approach
1. Replace manual 3-D index/region walking with `itk::ImageRegionIterator` / `itk::ShapedNeighborhoodIterator` as appropriate, so the algorithm becomes dimension-generic rather than 3-D-only and drops its bespoke bounds logic.
2. Convert the algorithm body into a proper `itk::ImageToImageFilter` subclass with normal pipeline semantics (streaming-aware `GenerateInputRequestedRegion` / `EnlargeOutputRequestedRegion` rather than the current unconditional `SetRequestedRegionToLargestPossibleRegion()` + exception).
3. Evaluate whether the vendored `FibHeap` can be replaced with a standard priority queue; if not, keep it but confine it behind the filter.
4. Behavior-preservation gate: keep `itkFastGrowCutRegressionTest` and the `DzZ_L1` / `DzZ_T1` baselines green. A pure iteration-strategy refactor must not change baselines.
Contributor guide
Research direction
Read Modules/Segmentation/GrowCut/include/itkFastGrowCut.h and itkFastGrowCut.hxx first, then inspect FibHeap.h and src/FibHeap.cxx. Run itkFastGrowCutRegressionTest with the DzZ_L1 and DzZ_T1 baselines before changing anything. Done means standard ITK iteration and pipeline semantics replace the manual region handling without changing those regression results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-vision
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100