Skip to content
Merged
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 @@ -305,8 +305,8 @@ class ITK_TEMPLATE_EXPORT ParzenWindowHistogramImageToImageMetric
PDFValueType * parzenValues);

/** Multiply the pdf entries by the given normalization factor. */
void
NormalizeJointPDF(JointPDFType * pdf, const double factor) const;
static void
NormalizeJointPDF(JointPDFType * pdf, const double factor);

/** Compute marginal pdfs by summing over the joint pdf
* direction = 0: fixed marginal pdf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "itkBSplineDerivativeKernelFunction2.h"
#include "itkImageLinearIteratorWithIndex.h"
#include "itkImageScanlineIterator.h"
#include <itkImageBufferRange.h>
#include <vnl/vnl_math.h>
#include <cassert>

Expand Down Expand Up @@ -606,19 +607,11 @@ ParzenWindowHistogramImageToImageMetric<TFixedImage, TMovingImage>::UpdateJointP
template <typename TFixedImage, typename TMovingImage>
void
ParzenWindowHistogramImageToImageMetric<TFixedImage, TMovingImage>::NormalizeJointPDF(JointPDFType * pdf,
const double factor) const
const double factor)
{
using JointPDFIteratorType = ImageScanlineIterator<JointPDFType>;
JointPDFIteratorType it(pdf, pdf->GetBufferedRegion());
const auto castfac = static_cast<PDFValueType>(factor);
while (!it.IsAtEnd())
for (PDFValueType & pdfValue : ImageBufferRange(*pdf))
{
while (!it.IsAtEndOfLine())
{
it.Value() *= castfac;
++it;
}
it.NextLine();
pdfValue *= factor;
}

} // end NormalizeJointPDF()
Expand Down
1 change: 1 addition & 0 deletions Common/GTesting/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(ELX_COMMON_GTEST_SOURCES
itkImageRandomSamplerSparseMaskGTest.cxx
itkImageSamplerGTest.cxx
itkParameterMapInterfaceTest.cxx
itkParzenWindowHistogramImageToImageMetricGTest.cxx
)

if(USE_ImpactMetric)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*=========================================================================
*
* Copyright UMC Utrecht and contributors
*
* 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
*
* http://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 "itkParzenWindowHistogramImageToImageMetric.h"
#include <itkImageBufferRange.h>
#include "GTesting/elxCoreMainGTestUtilities.h"
#include <gtest/gtest.h>

// The template to be tested.
using itk::ParzenWindowHistogramImageToImageMetric;
using elx::CoreMainGTestUtilities::CreateImageFilledWithSequenceOfNaturalNumbers;


// Checks the protected member function NormalizeJointPDF.
GTEST_TEST(ParzenWindowHistogramImageToImageMetric, NormalizeJointPDF)
{
using ImageType = itk::Image<int>;
using ParzenWindowHistogramImageToImageMetricType = ParzenWindowHistogramImageToImageMetric<ImageType, ImageType>;

class DerivedMetric : ParzenWindowHistogramImageToImageMetricType
{
public:
static void
TestNormalizeJointPDF(const double factor)
{
const auto pdf = CreateImageFilledWithSequenceOfNaturalNumbers<PDFValueType>(itk::Size<>{ 4, 5 });

const itk::ImageBufferRange imageBufferRange(*pdf);

const std::vector<PDFValueType> originalPDFValues(imageBufferRange.cbegin(), imageBufferRange.cend());

ParzenWindowHistogramImageToImageMetricType::NormalizeJointPDF(pdf, factor);

auto originalPDFValueIterator = originalPDFValues.cbegin();

for (const PDFValueType pixelValue : imageBufferRange)
{
EXPECT_EQ(pixelValue, *originalPDFValueIterator * factor);
++originalPDFValueIterator;
}
}
};

for (const auto factor : { 0.0, 0.5, 1.0 })
{
DerivedMetric::TestNormalizeJointPDF(factor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ParzenWindowMutualInformationImageToImageMetric<TFixedImage, TMovingImage>::GetV
this->ComputePDFs(parameters);

/** Normalize the pdfs: p = alpha h. */
this->NormalizeJointPDF(this->m_JointPDF, this->m_Alpha);
Superclass::NormalizeJointPDF(this->m_JointPDF, this->m_Alpha);

/** Compute the fixed and moving marginal pdfs, by summing over the joint pdf. */
this->ComputeMarginalPDF(this->m_JointPDF, this->m_FixedImageMarginalPDF, 0);
Expand Down Expand Up @@ -156,7 +156,7 @@ ParzenWindowMutualInformationImageToImageMetric<TFixedImage, TMovingImage>::GetV
this->ComputePDFsAndPDFDerivatives(parameters);

/** Normalize the pdfs: p = alpha h. */
this->NormalizeJointPDF(this->m_JointPDF, this->m_Alpha);
Superclass::NormalizeJointPDF(this->m_JointPDF, this->m_Alpha);

/** Compute the fixed and moving marginal pdf by summing over the histogram. */
this->ComputeMarginalPDF(this->m_JointPDF, this->m_FixedImageMarginalPDF, 0);
Expand Down Expand Up @@ -245,7 +245,7 @@ ParzenWindowMutualInformationImageToImageMetric<TFixedImage, TMovingImage>::GetV
this->ComputePDFs(parameters);

/** Normalize the joint histogram by alpha. */
this->NormalizeJointPDF(this->m_JointPDF, this->m_Alpha);
Superclass::NormalizeJointPDF(this->m_JointPDF, this->m_Alpha);

/** Compute the fixed and moving marginal pdf by summing over the histogram. */
this->ComputeMarginalPDF(this->m_JointPDF, this->m_FixedImageMarginalPDF, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ ParzenWindowNormalizedMutualInformationImageToImageMetric<TFixedImage, TMovingIm
this->ComputePDFs(parameters);

/** Normalize the pdfs: p = alpha h */
this->NormalizeJointPDF(this->m_JointPDF, this->m_Alpha);
Superclass::NormalizeJointPDF(this->m_JointPDF, this->m_Alpha);

/** Compute the fixed and moving marginal pdfs, by summing over the joint pdf */
this->ComputeMarginalPDF(this->m_JointPDF, this->m_FixedImageMarginalPDF, 0);
Expand Down Expand Up @@ -186,7 +186,7 @@ ParzenWindowNormalizedMutualInformationImageToImageMetric<TFixedImage, TMovingIm
this->ComputePDFsAndPDFDerivatives(parameters);

/** Normalize the pdfs: p = alpha h*/
this->NormalizeJointPDF(this->m_JointPDF, this->m_Alpha);
Superclass::NormalizeJointPDF(this->m_JointPDF, this->m_Alpha);

/** Compute the fixed and moving marginal pdf by summing over the histogram */
this->ComputeMarginalPDF(this->m_JointPDF, this->m_FixedImageMarginalPDF, 0);
Expand Down
Loading