diff --git a/Modules/Registration/Metricsv4/test/itkMattesMutualInformationImageToImageMetricv4Test.cxx b/Modules/Registration/Metricsv4/test/itkMattesMutualInformationImageToImageMetricv4Test.cxx index 9ac1fca1d13..ebfa0112b84 100644 --- a/Modules/Registration/Metricsv4/test/itkMattesMutualInformationImageToImageMetricv4Test.cxx +++ b/Modules/Registration/Metricsv4/test/itkMattesMutualInformationImageToImageMetricv4Test.cxx @@ -49,7 +49,10 @@ */ template int -TestMattesMetricWithAffineTransform(TInterpolator * const interpolator, const bool useSampling, const size_t imageSize) +TestMattesMetricWithAffineTransform(TInterpolator * const interpolator, + const bool useSampling, + const size_t imageSize, + const bool initializeFixedImage = true) { //------------------------------------------------------------ @@ -84,7 +87,7 @@ TestMattesMetricWithAffineTransform(TInterpolator * const interpolator, const bo auto imgFixed = FixedImageType::New(); imgFixed->SetRegions(region); - imgFixed->Allocate(); + imgFixed->Allocate(true); imgFixed->SetSpacing(imgSpacing); imgFixed->SetOrigin(imgOrigin); @@ -120,6 +123,7 @@ TestMattesMetricWithAffineTransform(TInterpolator * const interpolator, const bo ++ri; } } + if (initializeFixedImage) { TargetIteratorType ti(imgFixed, region); ti.GoToBegin(); @@ -462,6 +466,14 @@ itkMattesMutualInformationImageToImageMetricv4Test(int, char *[]) std::cout << "Test failed when using all the pixels instead of sampling" << std::endl; return EXIT_FAILURE; } + bool initializeFixedImage = false; + failed = TestMattesMetricWithAffineTransform( + linearInterpolator, useSampling, imageSize, initializeFixedImage); + if (failed) + { + std::cout << "Test failed when all fixed image pixels have the same value" << std::endl; + return EXIT_FAILURE; + } useSampling = true; failed = TestMattesMetricWithAffineTransform(linearInterpolator, useSampling, imageSize);