-
-
Notifications
You must be signed in to change notification settings - Fork 727
ENH: Ingest MultipleImageIterator into Modules/Core #6263
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 21 commits into
InsightSoftwareConsortium:main
from
hjmjohnson:ingest-MultipleImageIterator
May 13, 2026
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
8bcf0df
ENH: Original source code
dzenanz 888b1e3
ENH: reorganizing files into a remote module
dzenanz b579170
COMP: Compiles and passes style check
dzenanz f8a9ee8
ENH: Passes the test
dzenanz 6d13b97
ENH: Putting data to Midas
dzenanz 57a3afd
ENH: non-random way to calculate the output
dzenanz af619e5
STYLE: Modernize to C++11 conventions
hjmjohnson 0f28199
STYLE: Merge pull request #2 from KitwareMedical/ITKv5Style
hjmjohnson 5ea3203
STYLE: Prefer C++11 type alias over typedef
hjmjohnson 1ed2fba
STYLE: Merge pull request #3 from KitwareMedical/ITKv5Style
hjmjohnson d66ba97
DOC: Update copyright assignment to NumFOCUS
hjmjohnson 3ccfce4
ENH: Fix CI (hashes MD5->SHA512, bump CMake version, ITK 5.3RC3)
dzenanz e4adcef
ENH: Bump ITK and change http to https
tbirdso eaf9b0c
BUG: Fix test library variable name
blowekamp 2e6d462
ENH: Convert from md5 to .cid tags.
hjmjohnson 4903234
ENH: Merge pull request #17 from hjmjohnson/update-cid-tags
hjmjohnson 7536dde
ENH: Ingest ITKMultipleImageIterator into Modules/Core
hjmjohnson b641bf1
DOC: Add MultipleImageIterator README and clean module scaffolding
hjmjohnson 4a244ab
COMP: Remove MultipleImageIterator .remote.cmake (in-tree)
hjmjohnson 70ff6b6
ENH: Enable Module_MultipleImageIterator in configure-ci
hjmjohnson a1a0d48
STYLE: Address greptile review on MultipleImageIterator
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
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,3 @@ | ||
| project(MultipleImageIterator) | ||
|
|
||
| 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,24 @@ | ||
| # MultipleImageIterator | ||
|
|
||
| In-tree ITK module providing `itk::MultipleImageIterator`, a single | ||
| iterator that walks any number of co-registered images in lockstep. | ||
| The iterator returns a `std::vector` of pixel values (or references) | ||
| at each position, simplifying multi-channel processing without the | ||
| boilerplate of synchronizing N separate iterators. | ||
|
|
||
| ## Origin | ||
|
|
||
| Ingested from the standalone remote module | ||
| [**KitwareMedical/MultipleImageIterator**](https://github.com/KitwareMedical/MultipleImageIterator) | ||
| on 2026-05-12, following the v4 ingestion guidelines defined in | ||
| InsightSoftwareConsortium/ITK#6204. Placed under `Modules/Core/` to | ||
| match the placement of other ITK iterators (`itkImageRegionIterator`, | ||
| `itkNeighborhoodIterator`). The upstream repository will be archived | ||
| read-only after this PR merges; it remains reachable at the URL above | ||
| for historical reference. | ||
|
|
||
| ## References | ||
|
|
||
| - Schaerer J. *A MultipleImageIterator for iterating over multiple | ||
| images simultaneously.* The Insight Journal. December 2014. | ||
| <https://doi.org/10.54294/e5lmyz> |
99 changes: 99 additions & 0 deletions
99
Modules/Core/MultipleImageIterator/include/itkMultipleImageIterator.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,99 @@ | ||
| /*========================================================================= | ||
| * | ||
| * 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 itkMultipleImageIterator_h | ||
| #define itkMultipleImageIterator_h | ||
| #include <vector> | ||
| #include <itkImageRegionIterator.h> | ||
|
|
||
|
|
||
| namespace itk | ||
| { | ||
| /** \class MultipleImageIterator | ||
| * \brief An wrapper around image iterators to iterate over several images simultaneously | ||
| * All iterators must | ||
| * - point to images of the same type | ||
| * - be of the same size (number of values from begin to end) | ||
| * \ingroup ImageIterators | ||
| * \ingroup MultipleImageIterator */ | ||
| template <typename TIterator> | ||
| class MultipleImageIterator | ||
| { | ||
| public: | ||
| using Self = MultipleImageIterator; | ||
| using IteratorType = TIterator; | ||
| using ImageType = typename IteratorType::ImageType; | ||
| /// Access one of the iterators | ||
| IteratorType & | ||
| operator[](const unsigned int i) | ||
| { | ||
| return m_Iterators[i]; | ||
| } | ||
| /// Add a new iterator | ||
| void | ||
| AddIterator(const IteratorType & it) | ||
| { | ||
| m_Iterators.push_back(it); | ||
| } | ||
| /// Advance all iterators | ||
| Self & | ||
| operator++() | ||
| { | ||
| for (auto it = m_Iterators.begin(); it != m_Iterators.end(); ++it) | ||
| { | ||
| ++(*it); | ||
| } | ||
| return *this; | ||
| } | ||
| /// Rewind all iterators | ||
| void | ||
| GoToBegin() | ||
| { | ||
| for (auto it = m_Iterators.begin(); it != m_Iterators.end(); ++it) | ||
| { | ||
| it->GoToBegin(); | ||
| } | ||
| } | ||
| /** Check if the first iterator is at end. In debug mode, additionally check | ||
| * that at least one iterator is present and that all iterators' IsAtEnd() | ||
| * methods return the same thing */ | ||
| bool | ||
| IsAtEnd() | ||
| { | ||
| #ifdef NDEBUG | ||
| return m_Iterators[0].IsAtEnd(); | ||
| #else | ||
| assert(m_Iterators.size()); | ||
| bool retval = m_Iterators[0].IsAtEnd(); | ||
| for (unsigned int i = 0; i < m_Iterators.size(); ++i) | ||
| assert(m_Iterators[i].IsAtEnd() == retval); | ||
| return retval; | ||
| #endif | ||
| } | ||
| /// Returns the number of iterators | ||
| unsigned int | ||
| Size() const | ||
| { | ||
| return m_Iterators.size(); | ||
| } | ||
|
|
||
| protected: | ||
| std::vector<IteratorType> m_Iterators; | ||
| }; | ||
| } // namespace itk | ||
| #endif // itkMultipleImageIterator_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,11 @@ | ||
| # Maintainer: Joel Schaerer | ||
| itk_module( | ||
| MultipleImageIterator | ||
| DEPENDS | ||
| ITKCommon | ||
| TEST_DEPENDS | ||
| ITKTestKernel | ||
| EXCLUDE_FROM_DEFAULT | ||
| DESCRIPTION | ||
| "An iterator wrapper that walks multiple co-registered images in lockstep, returning a std::vector of pixel values at each position. https://doi.org/10.54294/e5lmyz" | ||
| ) |
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,19 @@ | ||
| itk_module_test() | ||
|
|
||
| set(MultipleImageIteratorTests DumpIntensities.cxx) | ||
|
|
||
| createtestdriver(MultipleImageIterator "${MultipleImageIterator-Test_LIBRARIES}" "${MultipleImageIteratorTests}") | ||
|
|
||
| itk_add_test( | ||
| NAME MultipleImageIteratorTest | ||
| COMMAND | ||
| MultipleImageIteratorTestDriver | ||
| --compare | ||
| DATA{randBase.nrrd} | ||
| "${ITK_TEST_OUTPUT_DIR}/randOut.nrrd" | ||
| DumpIntensities | ||
| "${ITK_TEST_OUTPUT_DIR}/randOut.nrrd" | ||
| DATA{img1.png} | ||
| DATA{img2.png} | ||
| DATA{img3.png} | ||
| ) |
95 changes: 95 additions & 0 deletions
95
Modules/Core/MultipleImageIterator/test/DumpIntensities.cxx
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,95 @@ | ||
| /*========================================================================= | ||
| * | ||
| * 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. | ||
| * | ||
| *=========================================================================*/ | ||
|
|
||
| #include <iostream> | ||
| #include <vector> | ||
| #include <string> | ||
| #include <cstdlib> | ||
| #include <itkImageFileReader.h> | ||
| #include <itkImageFileWriter.h> | ||
| #include "itkMultipleImageIterator.h" | ||
|
|
||
| // Dumps random samples from files into a csv file | ||
|
|
||
| int | ||
| DumpIntensities(int argc, char * argv[]) | ||
| { | ||
| if (argc < 3) | ||
| { | ||
| std::cerr << "Usage: DumpIntensities outfile inImage [inImage ...]" << std::endl; | ||
| return 1; | ||
| } | ||
| using PixelType = unsigned short; | ||
| using ImageType = itk::Image<PixelType, 3>; | ||
| using ReaderType = itk::ImageFileReader<ImageType>; | ||
|
|
||
| using IteratorType = itk::ImageRegionIterator<ImageType>; | ||
| itk::MultipleImageIterator<IteratorType> it; | ||
|
|
||
| std::vector<ImageType::Pointer> images; // Need to keep a reference as iterators only have weak references | ||
| for (int i = 2; i < argc; ++i) | ||
| { | ||
| ReaderType::Pointer r = ReaderType::New(); | ||
| r->SetFileName(argv[i]); | ||
| r->Update(); | ||
| ImageType::Pointer im = r->GetOutput(); | ||
| im->DisconnectPipeline(); | ||
| images.push_back(im); | ||
| it.AddIterator(itk::ImageRegionIterator<ImageType>(im, im->GetLargestPossibleRegion())); | ||
| } | ||
|
|
||
| unsigned long long c = 0; | ||
| using Vec3 = itk::FixedArray<PixelType, 3>; | ||
| std::vector<Vec3> values; | ||
| for (it.GoToBegin(); !it.IsAtEnd(); ++it, ++c) | ||
| { | ||
| if (c % 42 == 0) | ||
| { | ||
| Vec3 v; | ||
| for (unsigned int i = 0; i < it.Size(); ++i) | ||
| { | ||
| v[i] = it[i].Get(); | ||
| } | ||
| values.push_back(v); | ||
| } | ||
| } | ||
|
|
||
| using Image1D = itk::Image<Vec3, 1>; | ||
| Image1D::RegionType region; | ||
| region.SetIndex(0, 0); | ||
| region.SetSize(0, values.size()); | ||
| Image1D::Pointer randImage = Image1D::New(); | ||
| randImage->SetRegions(region); | ||
| randImage->Allocate(); | ||
|
|
||
| int index = 0; | ||
| itk::ImageRegionIterator<Image1D> oIt(randImage, randImage->GetLargestPossibleRegion()); | ||
| while (!oIt.IsAtEnd()) | ||
| { | ||
| oIt.Set(values[index++]); | ||
| ++oIt; | ||
| } | ||
|
|
||
| using WriterType = itk::ImageFileWriter<Image1D>; | ||
| WriterType::Pointer writer = WriterType::New(); | ||
| writer->SetInput(randImage); | ||
| writer->SetFileName(argv[1]); | ||
| writer->Update(); | ||
|
|
||
| return 0; | ||
| } |
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 @@ | ||
| bafkreicd6xi33oatbqzspxkeszliv3mmjnnmiiu6dj6qj6wuclkv7uokda |
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 @@ | ||
| bafkreiactetnzqheknc2zjeg6aoo6y7uqbid7oukpwttfjuj52stok6wbe |
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 @@ | ||
| bafkreibqkbie3ezhl2y2kvgfizpoj5qfz3y5xdbe5rqtjo35pb5zn5geti |
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 @@ | ||
| bafkreihso7ziayrcpwm22dbjctew7ju3a7egxdyoytdn4ueuwggu26tscq |
This file was deleted.
Oops, something went wrong.
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
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.