Skip to content

Commit

Permalink
ENH: Add elastix parameter "UseSamplingForGroupwiseRegistration"
Browse files Browse the repository at this point in the history
Allows elastix users to specify that the image sampling is used for group-wise registration:

    (UseSamplingForGroupwiseRegistration "true")

Aims to implement a generalization to the ReducedFullSampler, pull request #52 proposed by Mathias Polfliet in 2018.
  • Loading branch information
N-Dekker committed Apr 5, 2024
1 parent 23aad88 commit b41eb07
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Common/GTesting/itkImageFullSamplerGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,42 @@ GTEST_TEST(ImageFullSampler, ExactlyEqualVersusSlightlyDifferentMaskImageDomain)
EXPECT_FALSE(samplesOnExactlyEqualImageDomains.empty());

EXPECT_EQ(samplesOnExactlyEqualImageDomains, samplesOnSlightlyDifferentImageDomains);
}


GTEST_TEST(ImageFullSampler, UseForGroupwiseRegistration)
{
using PixelType = std::uint8_t;
static constexpr auto Dimension = 3U;
using ImageType = itk::Image<PixelType, Dimension>;
using ImageFullSamplerType = itk::ImageFullSampler<ImageType>;

std::mt19937 randomNumberEngine{};
const auto imageDomain = CreateRandomImageDomain<Dimension>(randomNumberEngine);
const auto image = CreateImageFilledWithSequenceOfNaturalNumbers<PixelType>(imageDomain);
elx::DefaultConstruct<ImageFullSamplerType> sampler{};

sampler.SetInput(image);
sampler.UseForGroupwiseRegistration();
sampler.Update();

const auto & output = DerefRawPointer(sampler.GetOutput());

const auto reducedRegion = [imageDomain] {
auto size = imageDomain.size;
size.back() = 1;
return itk::ImageRegion<Dimension>{ imageDomain.index, size };
}();

const itk::ImageRegionRange imageRegionRange(*image, reducedRegion);
const std::size_t numberOfSamples{ output.size() };

ASSERT_EQ(numberOfSamples, imageRegionRange.size());

auto imageRegionIterator = imageRegionRange.cbegin();
for (std::size_t i{}; i < numberOfSamples; ++i)
{
EXPECT_EQ(output[i].m_ImageValue, *imageRegionIterator);
++imageRegionIterator;
}
}
9 changes: 9 additions & 0 deletions Common/ImageSamplers/itkImageSamplerBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ class ITK_TEMPLATE_EXPORT ImageSamplerBase
/** Allows disabling the use of multi-threading, by `SetUseMultiThread(false)`. */
itkSetMacro(UseMultiThread, bool);

/** Tells that the sampler is used for groupwise registration. */
void
UseForGroupwiseRegistration()
{
m_UseForGroupwiseRegistration = true;
}

protected:
/** The constructor. */
ImageSamplerBase();
Expand Down Expand Up @@ -264,6 +271,8 @@ class ITK_TEMPLATE_EXPORT ImageSamplerBase

InputImageRegionType m_CroppedInputImageRegion{};
InputImageRegionType m_DummyInputImageRegion{};

bool m_UseForGroupwiseRegistration{ false };
};

} // end namespace itk
Expand Down
6 changes: 6 additions & 0 deletions Common/ImageSamplers/itkImageSamplerBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ ImageSamplerBase<TInputImage>::CropInputImageRegion()
* InputImageRegion and the BoundingBoxRegion.
*/
m_CroppedInputImageRegion = m_InputImageRegion;

if (m_UseForGroupwiseRegistration)
{
m_CroppedInputImageRegion.GetModifiableSize().back() = 1;
}

if (!m_Mask.IsNull())
{
/** Get a handle to the input image. */
Expand Down
4 changes: 4 additions & 0 deletions Core/ComponentBaseClasses/elxImageSamplerBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ ImageSamplerBase<TElastix>::BeforeRegistrationBase()
const Configuration & configuration = Deref(Superclass::GetConfiguration());
ITKBaseType & sampler = GetSelf();
sampler.SetUseMultiThread(configuration.RetrieveParameterValue(true, "UseMultiThreadingForSamplers", 0, false));
if (configuration.RetrieveParameterValue(false, "UseSamplingForGroupwiseRegistration", 0, false))
{
sampler.UseForGroupwiseRegistration();
}
}

/**
Expand Down

0 comments on commit b41eb07

Please sign in to comment.