Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ class ITK_TEMPLATE_EXPORT GradientDifferenceImageToImageMetric : public ImageToI
itkSetMacro(DerivativeDelta, double);
itkGetConstReferenceMacro(DerivativeDelta, double);
/** @ITKEndGrouping */

/** Allows specifying whether or not the Sobel operators should use the legacy coordinate values, compatible with ITK
* <= 5.4.
* \sa SobelOperator::SetUseLegacyCoefficients */
void
UseLegacySobelOperatorCoordinates(const bool useLegacyCoefficients);

/** Tells whether or not the Sobel operators are using the legacy coordinate values, compatible with ITK <= 5.4.
* \sa SobelOperator::SetUseLegacyCoefficients */
bool
IsUsingLegacySobelOperatorCoordinates() const
{
// It is sufficient to just check the first operator, because this property is the same for all operators.
return m_FixedSobelOperators[0].IsUsingLegacyCoefficients();
}

protected:
GradientDifferenceImageToImageMetric();
~GradientDifferenceImageToImageMetric() override = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ GradientDifferenceImageToImageMetric<TFixedImage, TMovingImage>::Initialize()
}
}


template <typename TFixedImage, typename TMovingImage>
void
GradientDifferenceImageToImageMetric<TFixedImage, TMovingImage>::UseLegacySobelOperatorCoordinates(
const bool useLegacyCoefficients)
{
if (useLegacyCoefficients != IsUsingLegacySobelOperatorCoordinates())
{
for (auto & sobelOperator : m_FixedSobelOperators)
{
sobelOperator.UseLegacyCoefficients(useLegacyCoefficients);
}
for (auto & sobelOperator : m_MovedSobelOperators)
{
sobelOperator.UseLegacyCoefficients(useLegacyCoefficients);
}
this->Modified();
}
}


template <typename TFixedImage, typename TMovingImage>
void
GradientDifferenceImageToImageMetric<TFixedImage, TMovingImage>::PrintSelf(std::ostream & os, Indent indent) const
Expand Down
6 changes: 5 additions & 1 deletion Modules/Registration/Common/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,11 @@ itk_add_test(
1
)

set(ITKRegistrationGTests itkTransformInitializersGTest.cxx)
set(
ITKRegistrationGTests
itkGradientDifferenceImageToImageMetricGTest.cxx
itkTransformInitializersGTest.cxx
)
creategoogletestdriver(ITKRegistration "${ITKRegistrationCommon-Test_LIBRARIES}" "${ITKRegistrationGTests}")

if(BUILD_EXAMPLES)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*=========================================================================
*
* 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.
*
*=========================================================================*/

// First include the header file to be tested:
#include "itkGradientDifferenceImageToImageMetric.h"
#include "itkImage.h"
#include <gtest/gtest.h>


TEST(GradientDifferenceImageToImageMetric, UseLegacySobelOperatorCoordinates)
{
using ImageType = itk::Image<float, 2>;
const auto metric = itk::GradientDifferenceImageToImageMetric<ImageType, ImageType>::New();

EXPECT_TRUE(metric->IsUsingLegacySobelOperatorCoordinates());

for (const bool useLegacyCoefficients : { false, true })
{
metric->UseLegacySobelOperatorCoordinates(useLegacyCoefficients);
EXPECT_EQ(metric->IsUsingLegacySobelOperatorCoordinates(), useLegacyCoefficients);
}
}
Loading