Skip to content

MarkovRandomFieldsClassifiers: Replace buffered region iteration in MRFImageFilter, remove iterator from RGBGibbsPriorFilter#5977

Merged
dzenanz merged 2 commits intoInsightSoftwareConsortium:mainfrom
N-Dekker:Replace-buffered-region-iterations-MarkovRandomFieldsClassifiers
Mar 24, 2026
Merged

MarkovRandomFieldsClassifiers: Replace buffered region iteration in MRFImageFilter, remove iterator from RGBGibbsPriorFilter#5977
dzenanz merged 2 commits intoInsightSoftwareConsortium:mainfrom
N-Dekker:Replace-buffered-region-iterations-MarkovRandomFieldsClassifiers

Conversation

@N-Dekker
Copy link
Copy Markdown
Contributor

@N-Dekker N-Dekker commented Mar 23, 2026

  • Replaced buffered region iteration with a FillBuffer(1) call in MRFImageFilter::Allocate()
  • Removed unused local region iterator labelledImageIt from RGBGibbsPriorFilter::GibbsEnergy

@github-actions github-actions Bot added the area:Segmentation Issues affecting the Segmentation module label Mar 23, 2026
Replaced a buffered region iteration with the equivalent (but more efficient)
`FillBuffer` call, in `MRFImageFilter::Allocate()`.

Follow-up to pull request InsightSoftwareConsortium#5970
"Replace buffered region iteration with FillBuffer in FastMarching filters"
This particular member function never used its local `labelledImageIt` variable.
@N-Dekker N-Dekker force-pushed the Replace-buffered-region-iterations-MarkovRandomFieldsClassifiers branch from fbc8b32 to e0ccde0 Compare March 23, 2026 21:40
@N-Dekker N-Dekker changed the title MarkovRandomFieldsClassifiers: Replace buffered region iterations in MRFImageFilter, remove iterator from RGBGibbsPriorFilter MarkovRandomFieldsClassifiers: Replace buffered region iteration in MRFImageFilter, remove iterator from RGBGibbsPriorFilter Mar 23, 2026
@N-Dekker N-Dekker marked this pull request as ready for review March 24, 2026 09:05
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 24, 2026

Greptile Summary

This PR makes two small, clean cleanups to the MarkovRandomFieldsClassifiers module: replacing a manual buffered-region iterator loop with FillBuffer(1) in MRFImageFilter::Allocate(), and removing a dead-code iterator variable from RGBGibbsPriorFilter::GibbsEnergy.

  • itkMRFImageFilter.hxx: The while (!rIter.IsAtEnd()) loop that initialized every pixel to 1 is replaced with m_LabelStatusImage->FillBuffer(1). Both operate over the buffered region and produce identical results; FillBuffer is the more idiomatic ITK approach and may use a more efficient memory fill internally. The LabelStatusImageIterator type alias in the header is retained and remains used in ApplyMRFImageFilter().
  • itkRGBGibbsPriorFilter.hxx: The LabelledImageRegionIterator labelledImageIt local variable was constructed at the top of GibbsEnergy but never read or advanced — the function accesses m_LabelledImage exclusively through direct GetPixel() calls. Removing it eliminates an unnecessary iterator construction over the entire buffered region on every call to this function. The type is still legitimately used in other methods of the same file.

Confidence Score: 5/5

  • This PR is safe to merge — both changes are purely mechanical, semantics-preserving cleanups with no behavioural impact.
  • The FillBuffer(1) replacement is functionally identical to the loop it replaces; the removed iterator in GibbsEnergy was confirmed dead code via a full grep of usages across the module. No logic is altered, no type aliases are orphaned, and no edge cases are introduced.
  • No files require special attention.

Important Files Changed

Filename Overview
Modules/Segmentation/MarkovRandomFieldsClassifiers/include/itkMRFImageFilter.hxx Replaces a manual while-loop iterator with FillBuffer(1) in Allocate(). The LabelStatusImageIterator type alias remains in the header and is still used in ApplyMRFImageFilter(), so no type is orphaned. The change is functionally equivalent and more idiomatic.
Modules/Segmentation/MarkovRandomFieldsClassifiers/include/itkRGBGibbsPriorFilter.hxx Removes an unused LabelledImageRegionIterator labelledImageIt local variable from GibbsEnergy. The function accesses m_LabelledImage directly via GetPixel(), so the iterator was truly dead code. LabelledImageRegionIterator remains used in other methods.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["MRFImageFilter::Allocate()"] --> B["m_LabelStatusImage->Allocate()"]
    B --> C["m_LabelStatusImage->FillBuffer(1)\n✅ replaces manual iterator loop"]

    D["RGBGibbsPriorFilter::GibbsEnergy(i, k, k1)"] --> E["Compute offsetIndex3D from i"]
    E --> F["Access m_LabelledImage via GetPixel()"]
    F --> G["❌ labelledImageIt was constructed here\nbut never used — now removed"]
    F --> H["Return computed Gibbs energy"]
Loading

Reviews (1): Last reviewed commit: "STYLE: Remove `labelledImageIt` from `RG..." | Re-trigger Greptile

@dzenanz dzenanz merged commit 9077d0c into InsightSoftwareConsortium:main Mar 24, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Segmentation Issues affecting the Segmentation module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants