Skip to content

Commit

Permalink
STYLE: Remove UseMask property from ComputeImageExtremaFilter
Browse files Browse the repository at this point in the history
Assumed that ComputeImageExtremaFilter should use its mask, if and only if the mask is not null.
  • Loading branch information
N-Dekker committed Feb 19, 2024
1 parent 97fe5bb commit e99644c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 37 deletions.
13 changes: 2 additions & 11 deletions Common/CostFunctions/itkAdvancedImageToImageMetric.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,7 @@ AdvancedImageToImageMetric<TFixedImage, TMovingImage>::InitializeLimiters()

const auto computeFixedImageExtrema = ComputeImageExtremaFilter<FixedImageType>::New();
computeFixedImageExtrema->SetInput(this->GetFixedImage());
if (const auto * const fMask = this->GetFixedImageMask())
{
computeFixedImageExtrema->SetUseMask(true);
computeFixedImageExtrema->SetImageSpatialMask(fMask);
}

computeFixedImageExtrema->SetImageSpatialMask(this->GetFixedImageMask());
computeFixedImageExtrema->Update();

this->m_FixedImageTrueMax = computeFixedImageExtrema->GetMaximum();
Expand Down Expand Up @@ -228,11 +223,7 @@ AdvancedImageToImageMetric<TFixedImage, TMovingImage>::InitializeLimiters()

const auto computeMovingImageExtrema = ComputeImageExtremaFilter<MovingImageType>::New();
computeMovingImageExtrema->SetInput(this->GetMovingImage());
if (const auto * const mask = this->GetMovingImageMask())
{
computeMovingImageExtrema->SetUseMask(true);
computeMovingImageExtrema->SetImageSpatialMask(mask);
}
computeMovingImageExtrema->SetImageSpatialMask(this->GetMovingImageMask());
computeMovingImageExtrema->Update();

this->m_MovingImageTrueMax = computeMovingImageExtrema->GetMaximum();
Expand Down
4 changes: 0 additions & 4 deletions Common/GTesting/itkComputeImageExtremaFilterGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ Expect_one_non_zero_pixel_value_masked_in(const typename TImage::SizeType & imag
const auto filter = CheckNew<FilterType>();
filter->SetInput(image);
filter->SetImageSpatialMask(maskSpatialObject);
filter->SetUseMask(true);
filter->Update();

EXPECT_EQ(filter->GetMinimum(), pixelValue);
Expand Down Expand Up @@ -247,7 +246,6 @@ Expect_one_positive_pixel_value_all_pixels_masked_in(const typename TImage::Size
const auto filter = CheckNew<FilterType>();
filter->SetInput(image);
filter->SetImageSpatialMask(maskSpatialObject);
filter->SetUseMask(true);
filter->Update();

EXPECT_EQ(filter->GetMinimum(), 0);
Expand Down Expand Up @@ -356,8 +354,6 @@ GTEST_TEST(ComputeImageExtremaFilter, MaskSpacingAndDirectionAffectResults)
elastix::DefaultConstruct<FilterType> filter{};
filter.SetInput(image);
filter.SetImageSpatialMask(maskSpatialObject);
filter.SetUseMask(true);

filter.Update();
return filter.GetMaximum();
};
Expand Down
3 changes: 0 additions & 3 deletions Common/itkComputeImageExtremaFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class ITK_TEMPLATE_EXPORT ComputeImageExtremaFilter : public StatisticsImageFilt
/** Type to use for computations. */
using typename Superclass::RealType;

itkSetMacro(UseMask, bool);

using ImageSpatialMaskType = ImageMaskSpatialObject<Self::ImageDimension>;
using ImageSpatialMaskPointer = typename ImageSpatialMaskType::Pointer;
using ImageSpatialMaskConstPointer = typename ImageSpatialMaskType::ConstPointer;
Expand Down Expand Up @@ -105,7 +103,6 @@ class ITK_TEMPLATE_EXPORT ComputeImageExtremaFilter : public StatisticsImageFilt

private:
ImageSpatialMaskConstPointer m_ImageSpatialMask{};
bool m_UseMask{ false };
bool m_SameGeometry{ false };

CompensatedSummation<RealType> m_ThreadSum{ 1 };
Expand Down
11 changes: 4 additions & 7 deletions Common/itkComputeImageExtremaFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ template <typename TInputImage>
void
ComputeImageExtremaFilter<TInputImage>::BeforeStreamedGenerateData()
{
if (!this->m_UseMask)
if (m_ImageSpatialMask == nullptr)
{
Superclass::BeforeStreamedGenerateData();
}
Expand Down Expand Up @@ -57,7 +57,7 @@ template <typename TInputImage>
void
ComputeImageExtremaFilter<TInputImage>::AfterStreamedGenerateData()
{
if (!this->m_UseMask)
if (m_ImageSpatialMask == nullptr)
{
Superclass::AfterStreamedGenerateData();
}
Expand Down Expand Up @@ -89,16 +89,13 @@ template <typename TInputImage>
void
ComputeImageExtremaFilter<TInputImage>::ThreadedStreamedGenerateData(const RegionType & regionForThread)
{
if (!this->m_UseMask)
if (m_ImageSpatialMask == nullptr)
{
Superclass::ThreadedStreamedGenerateData(regionForThread);
}
else
{
if (this->GetImageSpatialMask())
{
this->ThreadedGenerateDataImageSpatialMask(regionForThread);
}
this->ThreadedGenerateDataImageSpatialMask(regionForThread);
}
} // end ThreadedGenerateData()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ AdvancedMeanSquaresImageToImageMetric<TFixedImage, TMovingImage>::Initialize()
/** Try to guess a normalization factor. */
const auto computeFixedImageExtrema = ComputeImageExtremaFilter<FixedImageType>::New();
computeFixedImageExtrema->SetInput(this->GetFixedImage());
if (const auto * const mask = this->GetFixedImageMask())
{
computeFixedImageExtrema->SetUseMask(true);
computeFixedImageExtrema->SetImageSpatialMask(mask);
}

computeFixedImageExtrema->SetImageSpatialMask(this->GetFixedImageMask());
computeFixedImageExtrema->Update();

this->m_FixedImageTrueMax = computeFixedImageExtrema->GetMaximum();
Expand All @@ -76,12 +71,7 @@ AdvancedMeanSquaresImageToImageMetric<TFixedImage, TMovingImage>::Initialize()

const auto computeMovingImageExtrema = ComputeImageExtremaFilter<MovingImageType>::New();
computeMovingImageExtrema->SetInput(this->GetMovingImage());
if (const auto * const mask = this->GetMovingImageMask())
{
computeMovingImageExtrema->SetUseMask(true);
computeMovingImageExtrema->SetImageSpatialMask(mask);
}

computeMovingImageExtrema->SetImageSpatialMask(this->GetMovingImageMask());
computeMovingImageExtrema->Update();

this->m_MovingImageTrueMax = computeMovingImageExtrema->GetMaximum();
Expand Down

0 comments on commit e99644c

Please sign in to comment.