-
-
Notifications
You must be signed in to change notification settings - Fork 726
ENH: Ingest ITKGenericLabelInterpolator into Modules/Filtering #6135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hjmjohnson
merged 43 commits into
InsightSoftwareConsortium:main
from
hjmjohnson:ingest-GenericLabelInterpolator
Apr 27, 2026
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
f30c6ba
ENH: Converting generic_label_interpolator to an ITK remote module.
fbudin69500 e107225
ENH: Replacing M_PI with itk::Math::pi
fbudin69500 fea9737
ENH: Remove unused variables warning
fbudin69500 4e0250b
BUG: m_Alpha and m_Sigma are private variables
fbudin69500 c93d77d
ENH: Require cmake minimum version to be 3.9.5.
bb73f94
ENH: ITKv5 override consistency
hjmjohnson 3828cfb
COMP: Use C++11 override directly
hjmjohnson 8478c95
COMP: Use nullptr instead of 0 or NULL
hjmjohnson 34267a5
STYLE: Modernize to C++11 conventions
hjmjohnson 08a743a
STYLE: Replace itkStaticConstMacro with static constexpr
hjmjohnson 091cd46
STYLE: Prefer C++11 type alias over typedef
hjmjohnson 45c6408
STYLE: Prefer constexpr for const numeric literals
hjmjohnson 0730ff7
COMP: Move ITK_DISALLOW_COPY_AND_ASSIGN calls to public section.
49c357f
COMP: Set the minimum required CMake version to 3.10.2.
4826360
ENH: Add missing CI components.
jhlegarreta 2bd5803
DOC: Improve the module documentation.
jhlegarreta a8dea93
COMP: Interpolators now must provide GetRadius()
hjmjohnson f0d92c6
STYLE: Use more ITKv5 style conformance.
hjmjohnson 2b56ef2
COMP: Missing constructor definition.
hjmjohnson 9e9ba84
ENH: Update itkLabelImageGenericInterpolateImageFunction.h
yinkaola c515874
ENH: Update itkLabelImageGenericInterpolateImageFunction.hxx
yinkaola f5cfa8a
STYLE: replacing MD5 hashes by SHA512 hashes
dzenanz d89fccd
STYLE: Use override statements for C++11
hjmjohnson 6dbbc10
STYLE: Prefer = default to explicitly trivial implementations
hjmjohnson 0ca1f92
STYLE: Use auto for variable type matches the type of the initializer…
hjmjohnson 36a9197
DOC: Update copyright assignment to NumFOCUS
hjmjohnson 0f6d673
ENH: Make similar to template
hjmjohnson 533abc6
COMP: Fix Wrapping Errors
sudomakeinstall 99f7439
STYLE: Rename ITK_DISALLOW_COPY_AND_ASSIGN to ITK_DISALLOW_COPY_AND_M…
mseng10 9b4a3b8
COMP: Remove inclusion of .hxx files as headers
hjmjohnson f365bca
ENH: update minimum required CMake version
dzenanz feee9c1
ENH: Bump ITK and replace http with https using script
tbirdso 4e6c239
COMP: Define interpolator template parameter names
thewtex ecce950
COMP: Use modern macro for name of class
hjmjohnson 195fdab
ENH: Reduce image size of rotate resampling test
blowekamp 790436d
ENH: Ingest ITKGenericLabelInterpolator into Modules/Filtering
hjmjohnson 4441e31
COMP: Drop missing README.rst read in ingested GenericLabelInterpolator
hjmjohnson e806372
COMP: Remove GenericLabelInterpolator.remote.cmake; now in-tree
hjmjohnson df55563
ENH: Enable GenericLabelInterpolator in CI via configure-ci
hjmjohnson c5cf2dd
ENH: Per-commit pre-commit replay for remote-module ingestion
hjmjohnson 45eece3
COMP: Drop standalone-build boilerplate from GenericLabelInterpolator
hjmjohnson 6c87ea0
DOC: Note post-merge autosquash hazard in ingestion rules
hjmjohnson 957dae2
DOC: Demand the root-commit ghostflow error for ingest PRs
hjmjohnson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| itk_module_impl() |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # GenericLabelInterpolator | ||
|
|
||
| In-tree ITK module providing a generic interpolator for multi-label | ||
| images. `itk::LabelImageGenericInterpolateImageFunction` interpolates | ||
| each label independently with any ordinary image interpolator and | ||
| returns, at each query point, the label whose interpolated value is | ||
| highest. Generalizes the Gaussian-only behavior of | ||
| `itk::LabelImageGaussianInterpolateImageFunction`. | ||
|
|
||
| ## Origin | ||
|
|
||
| Ingested from the standalone remote module | ||
| [**InsightSoftwareConsortium/ITKGenericLabelInterpolator**](https://github.com/InsightSoftwareConsortium/ITKGenericLabelInterpolator) | ||
| on 2026-04-25, at upstream commit | ||
| [`081575cd`](https://github.com/InsightSoftwareConsortium/ITKGenericLabelInterpolator/commit/081575cdcc26b1a542d4c90feaf9250df5e104d9). | ||
| The upstream repository will be archived read-only after this PR | ||
| merges; it remains reachable at the URL above. | ||
|
|
||
| ## What lives here | ||
|
|
||
| Per the v3 ingestion strategy (see | ||
| `Utilities/Maintenance/RemoteModuleIngest/INGESTION_STRATEGY.md`), only | ||
| paths matching the narrow whitelist (code, headers, tests, wrapping, | ||
| module CMake) crossed the merge boundary: | ||
|
|
||
| - `include/` — public C++ headers. | ||
| - `test/` — CTest drivers and content-link stubs. | ||
| - `wrapping/` — Python wrapping descriptors. | ||
| - `CMakeLists.txt`, `itk-module.cmake` — build + module descriptors. | ||
|
|
||
| Every surviving commit preserves original authorship; `git blame` | ||
| walks across the merge boundary to upstream authors back to 2014. | ||
|
|
||
| ## What was intentionally left upstream | ||
|
|
||
| Everything outside the whitelist stays in the archived upstream repo. | ||
| If you need any of it, clone | ||
| <https://github.com/InsightSoftwareConsortium/ITKGenericLabelInterpolator>. | ||
|
|
||
| | Content in upstream | Why it did not ingest | | ||
| |---|---| | ||
| | `examples/` | Per-module `examples/` are routed to top-level [`Examples/`](https://github.com/InsightSoftwareConsortium/ITK/tree/main/Examples) via a separate follow-up PR. | | ||
| | `README.rst` | Algorithm citations + background are folded into the Doxygen on the filter headers and the module DESCRIPTION. | | ||
| | `.github/`, `azure-pipelines.yml`, `Dockerfile` | Standalone-build CI scaffolding; not useful in-tree. | | ||
| | `CTestConfig.cmake`, `pyproject.toml`, `LICENSE`, `.clang-format` | Packaging / CI / style scaffolding superseded by ITK root. | | ||
|
|
||
| ## Long-form documentation | ||
|
|
||
| - **Algorithm description** — see the Doxygen on | ||
| `itkLabelImageGenericInterpolateImageFunction`, plus the embedded | ||
| citation: | ||
|
|
||
| > Schaerer, J., Roche, F., Belaroussi, B. | ||
| > *A generic interpolator for multi-label images*. | ||
| > The Insight Journal, January–December 2014. | ||
| > <https://hdl.handle.net/10380/3506> | ||
|
|
||
| - **Standalone build + usage examples** — see the archived upstream at | ||
| <https://github.com/InsightSoftwareConsortium/ITKGenericLabelInterpolator>. | ||
|
|
||
| ## Content-link status | ||
|
|
||
| The 2 baseline / input content-links under `test/Baseline/` and | ||
| `test/Input/` are already in `.cid` (IPFS Content Identifier) form; | ||
| no `.md5` → `.cid` normalization is required for this module. |
133 changes: 133 additions & 0 deletions
133
...Filtering/GenericLabelInterpolator/include/itkLabelImageGenericInterpolateImageFunction.h
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| /*========================================================================= | ||
| * | ||
| * Copyright NumFOCUS | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0.txt | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| *=========================================================================*/ | ||
| #ifndef itkLabelImageGenericInterpolateImageFunction_h | ||
| #define itkLabelImageGenericInterpolateImageFunction_h | ||
|
|
||
| #include <itkInterpolateImageFunction.h> | ||
| #include "itkLabelSelectionImageAdaptor.h" | ||
| #include <vector> | ||
| #include <set> | ||
|
|
||
| namespace itk | ||
| { | ||
|
|
||
| /** \class LabelImageGenericInterpolateImageFunction | ||
| * \brief Interpolation function for multi-label images that implicitly interpolates each | ||
| * unique value in the image corresponding to each label set element and returns the | ||
| * corresponding label set element with the largest weight. | ||
| * | ||
| * This filter is an alternative to nearest neighbor interpolation for multi-label | ||
| * images. It can use almost any underlying interpolator. | ||
| * * \ingroup ITKImageFunction | ||
| * * \ingroup GenericLabelInterpolator | ||
| */ | ||
|
|
||
| template <typename TInputImage, | ||
| template <typename TInterpInputImage, typename TCoordRep> class TInterpolator, | ||
| typename TCoordRep = double> | ||
| class ITK_EXPORT LabelImageGenericInterpolateImageFunction : public InterpolateImageFunction<TInputImage, TCoordRep> | ||
| { | ||
| public: | ||
| ITK_DISALLOW_COPY_AND_MOVE(LabelImageGenericInterpolateImageFunction); | ||
|
|
||
| /** Standard class type alias. */ | ||
| using Self = LabelImageGenericInterpolateImageFunction; | ||
| using Superclass = InterpolateImageFunction<TInputImage, TCoordRep>; | ||
| using Pointer = SmartPointer<Self>; | ||
| using ConstPointer = SmartPointer<const Self>; | ||
| using InputPixelType = typename TInputImage::PixelType; | ||
|
|
||
| /** Run-time type information (and related methods). */ | ||
| itkOverrideGetNameOfClassMacro(LabelImageGenericInterpolateImageFunction); | ||
|
|
||
| /** Method for creation through the object factory. */ | ||
| itkNewMacro(Self); | ||
|
|
||
| /** ImageDimension constant */ | ||
| static constexpr unsigned int ImageDimension = TInputImage::ImageDimension; | ||
|
|
||
| /** OutputType type alias support. */ | ||
| using OutputType = typename Superclass::OutputType; | ||
|
|
||
| /** InputImageType type alias support. */ | ||
| using InputImageType = typename Superclass::InputImageType; | ||
|
|
||
| /** RealType type alias support. */ | ||
| using RealType = typename Superclass::RealType; | ||
|
|
||
| /** Index type alias support. */ | ||
| using IndexType = typename Superclass::IndexType; | ||
|
|
||
| /** Size type alias support. */ | ||
| using SizeType = typename Superclass::SizeType; | ||
|
|
||
| /** ContinuousIndex type alias support. */ | ||
| using ContinuousIndexType = typename Superclass::ContinuousIndexType; | ||
|
|
||
| using LabelSelectionAdaptorType = LabelSelectionImageAdaptor<TInputImage, double>; | ||
|
|
||
| // The interpolator used for individual binary masks corresponding to each label | ||
| using InternalInterpolatorType = TInterpolator<LabelSelectionAdaptorType, TCoordRep>; | ||
|
|
||
| /** | ||
| * Evaluate at the given index | ||
| */ | ||
| OutputType | ||
| EvaluateAtContinuousIndex(const ContinuousIndexType & cindex) const override | ||
| { | ||
| return this->EvaluateAtContinuousIndex(cindex, nullptr); | ||
| } | ||
|
|
||
| void | ||
| SetInputImage(const TInputImage * image) override; | ||
|
|
||
| /** Get the radius required for interpolation. | ||
| * | ||
| * This defines the number of surrounding pixels required to interpolate at | ||
| * a given point. | ||
| */ | ||
| SizeType | ||
| GetRadius() const override | ||
| { | ||
| return SizeType::Filled(1); | ||
| } | ||
|
|
||
| protected: | ||
| LabelImageGenericInterpolateImageFunction() = default; | ||
| ~LabelImageGenericInterpolateImageFunction() override = default; | ||
|
|
||
| std::vector<typename InternalInterpolatorType::Pointer> m_InternalInterpolators; | ||
| std::vector<typename LabelSelectionAdaptorType::Pointer> m_LabelSelectionAdaptors; | ||
| using LabelSetType = std::set<typename TInputImage::PixelType>; | ||
| LabelSetType m_Labels; | ||
|
|
||
| private: | ||
| /** | ||
| * Evaluate function value at the given index | ||
| */ | ||
| virtual OutputType | ||
| EvaluateAtContinuousIndex(const ContinuousIndexType &, OutputType *) const; | ||
| }; | ||
|
|
||
| } // end namespace itk | ||
|
|
||
| #ifndef ITK_MANUAL_INSTANTIATION | ||
| # include "itkLabelImageGenericInterpolateImageFunction.hxx" | ||
| #endif | ||
|
|
||
| #endif |
89 changes: 89 additions & 0 deletions
89
...ltering/GenericLabelInterpolator/include/itkLabelImageGenericInterpolateImageFunction.hxx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /*========================================================================= | ||
| * | ||
| * Copyright NumFOCUS | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0.txt | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| *=========================================================================*/ | ||
| #ifndef itkLabelImageGenericInterpolateImageFunction_hxx | ||
| #define itkLabelImageGenericInterpolateImageFunction_hxx | ||
|
|
||
| #include <itkImageRegionConstIterator.h> | ||
|
|
||
| namespace itk | ||
| { | ||
|
|
||
| template <typename TInputImage, | ||
| template <typename TInterpInputImage, typename TCoordRep> class TInterpolator, | ||
| typename TCoordRep> | ||
| void | ||
| LabelImageGenericInterpolateImageFunction<TInputImage, TInterpolator, TCoordRep>::SetInputImage( | ||
| const TInputImage * image) | ||
| { | ||
| /* We have one adaptor and one interpolator per label to keep the class thread-safe: | ||
| * changing the adaptor's accepted value wouldn't work when called from a multi-threaded filter */ | ||
| using IteratorType = itk::ImageRegionConstIterator<TInputImage>; | ||
| if (image) | ||
| { | ||
| m_Labels.clear(); | ||
| IteratorType it(image, image->GetLargestPossibleRegion()); | ||
| for (it.GoToBegin(); !it.IsAtEnd(); ++it) | ||
| { | ||
| m_Labels.insert(it.Get()); | ||
| } | ||
| m_InternalInterpolators.clear(); | ||
| m_LabelSelectionAdaptors.clear(); | ||
| for (auto i = m_Labels.begin(); i != m_Labels.end(); ++i) | ||
| { | ||
| typename LabelSelectionAdaptorType::Pointer adapt = LabelSelectionAdaptorType::New(); | ||
| // This adaptor doesn't implement Set() so this should be safe | ||
| adapt->SetImage(const_cast<TInputImage *>(image)); | ||
| adapt->SetAcceptedValue(*i); | ||
| m_LabelSelectionAdaptors.push_back(adapt); | ||
| typename InternalInterpolatorType::Pointer interp = InternalInterpolatorType::New(); | ||
| interp->SetInputImage(adapt); | ||
| m_InternalInterpolators.push_back(interp); | ||
| } | ||
| } | ||
| Superclass::SetInputImage(image); | ||
| } | ||
|
|
||
| template <typename TInputImage, | ||
| template <typename TInterpInputImage, typename TCoordRep> class TInterpolator, | ||
| typename TCoordRep> | ||
| typename LabelImageGenericInterpolateImageFunction<TInputImage, TInterpolator, TCoordRep>::OutputType | ||
| LabelImageGenericInterpolateImageFunction<TInputImage, TInterpolator, TCoordRep>::EvaluateAtContinuousIndex( | ||
| const ContinuousIndexType & cindex, | ||
| OutputType * itkNotUsed(grad)) const | ||
| { | ||
| /* Interpolate the binary mask corresponding to each label and return the label | ||
| * with the highest value */ | ||
| double value = 0; | ||
| InputPixelType best_label = itk::NumericTraits<InputPixelType>::ZeroValue(); | ||
| int i = 0; | ||
| for (auto it = m_Labels.begin(); it != m_Labels.end(); ++it) | ||
| { | ||
| double tmp = m_InternalInterpolators[i]->EvaluateAtContinuousIndex(cindex); | ||
| if (tmp > value) | ||
| { | ||
| value = tmp; | ||
| best_label = (*it); | ||
| } | ||
| ++i; | ||
| } | ||
| return best_label; | ||
| } | ||
|
|
||
| } // namespace itk | ||
|
|
||
| #endif | ||
68 changes: 68 additions & 0 deletions
68
Modules/Filtering/GenericLabelInterpolator/include/itkLabelSelectionImageAdaptor.h
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /*========================================================================= | ||
| * | ||
| * Copyright NumFOCUS | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0.txt | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| *=========================================================================*/ | ||
| #ifndef itkLabelSelectionImageAdaptor_h | ||
| #define itkLabelSelectionImageAdaptor_h | ||
|
|
||
| #include "itkLabelSelectionPixelAccessor.h" | ||
|
|
||
| namespace itk | ||
| { | ||
| /** \class LabelSelectionImageAdaptor | ||
| * \brief Presents a label image as a binary image of one label | ||
| * | ||
| * Additional casting is performed according to the input and output image | ||
| * types following C++ default casting rules. | ||
| * | ||
| * \ingroup ImageAdaptors | ||
| * \ingroup ITKImageAdaptors | ||
| * \ingroup GenericLabelInterpolator | ||
| */ | ||
| template <class TImage, class TOutputPixelType> | ||
| class ITK_EXPORT LabelSelectionImageAdaptor | ||
| : public ImageAdaptor<TImage, Accessor::LabelSelectionPixelAccessor<typename TImage::PixelType, TOutputPixelType>> | ||
| { | ||
| public: | ||
| ITK_DISALLOW_COPY_AND_MOVE(LabelSelectionImageAdaptor); | ||
|
|
||
| /** Standard class type alias. */ | ||
| using Self = LabelSelectionImageAdaptor; | ||
| using Superclass = | ||
| ImageAdaptor<TImage, Accessor::LabelSelectionPixelAccessor<typename TImage::PixelType, TOutputPixelType>>; | ||
|
|
||
| using Pointer = SmartPointer<Self>; | ||
| using ConstPointer = SmartPointer<const Self>; | ||
|
|
||
| /** Method for creation through the object factory. */ | ||
| itkNewMacro(Self); | ||
|
|
||
| /** Run-time type information (and related methods). */ | ||
| itkOverrideGetNameOfClassMacro(LabelSelectionImageAdaptor); | ||
|
|
||
| void | ||
| SetAcceptedValue(typename TImage::PixelType value) | ||
| { | ||
| this->GetPixelAccessor().SetAcceptedValue(value); | ||
| } | ||
|
|
||
| protected: | ||
| LabelSelectionImageAdaptor() = default; | ||
| ~LabelSelectionImageAdaptor() override = default; | ||
| }; | ||
| } // end namespace itk | ||
|
|
||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.