Skip to content
Open
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
1 change: 1 addition & 0 deletions Modules/Filtering/BiasCorrection/itk-module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ itk_module(
ITKImageGrid
ITKPolynomials
TEST_DEPENDS
ITKGoogleTest
ITKTestKernel
ITKOptimizers
ITKPolynomials
Expand Down
11 changes: 4 additions & 7 deletions Modules/Filtering/BiasCorrection/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
itk_module_test()
set(
ITKBiasCorrectionTests
itkCompositeValleyFunctionTest.cxx
itkMRIBiasFieldCorrectionFilterTest.cxx
itkN4BiasFieldCorrectionImageFilterTest.cxx
)

createtestdriver(ITKBiasCorrection "${ITKBiasCorrection-Test_LIBRARIES}" "${ITKBiasCorrectionTests}")

itk_add_test(
NAME itkCompositeValleyFunctionTest
COMMAND
ITKBiasCorrectionTestDriver
itkCompositeValleyFunctionTest
)
set(ITKBiasCorrectionGTests itkCompositeValleyFunctionGTest.cxx)

creategoogletestdriver(ITKBiasCorrection "${ITKBiasCorrection-Test_LIBRARIES}" "${ITKBiasCorrectionGTests}")

itk_add_test(
NAME itkMRIBiasFieldCorrectionFilterTest
COMMAND
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*=========================================================================
*
* 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.
*
*=========================================================================*/

#include "itkCompositeValleyFunction.h"
#include "itkMath.h"
#include <gtest/gtest.h>

TEST(CompositeValleyFunction, BoundsAndInterval)
{
itk::Array<double> means(2);
itk::Array<double> sigmas(2);

means[0] = 0.0;
means[1] = 100.0;
sigmas[0] = 20.0;
sigmas[1] = 20.0;

itk::CompositeValleyFunction function(means, sigmas);

EXPECT_DOUBLE_EQ(function.GetUpperBound(), 280.0);
EXPECT_DOUBLE_EQ(function.GetLowerBound(), -180.0);

const double interval1 = function.GetInterval();
const double interval2 = (function.GetUpperBound() - function.GetLowerBound()) / (1000000.0 - 1.0);
EXPECT_NEAR(interval1, interval2, itk::NumericTraits<double>::epsilon());
}

TEST(CompositeValleyFunction, EvaluateMatchesCallOperator)
{
itk::Array<double> means(2);
itk::Array<double> sigmas(2);

means[0] = 0.0;
means[1] = 100.0;
sigmas[0] = 20.0;
sigmas[1] = 20.0;

itk::CompositeValleyFunction function(means, sigmas);

const long numberOfSamples = function.GetNumberOfSamples();
const double measure = function.GetLowerBound() + function.GetInterval() * numberOfSamples * 0.5;
const double value1 = function(measure);
const double value2 = function.Evaluate(measure);

EXPECT_NEAR(value1, value2, itk::NumericTraits<double>::epsilon());
}

This file was deleted.

1 change: 1 addition & 0 deletions Modules/Filtering/Deconvolution/itk-module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ itk_module(
ITKConvolution
ITKImageSources
TEST_DEPENDS
ITKGoogleTest
ITKTestKernel
DESCRIPTION "${DOCUMENTATION}"
)
16 changes: 8 additions & 8 deletions Modules/Filtering/Deconvolution/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ set(
ITKDeconvolutionTests
itkInverseDeconvolutionImageFilterTest.cxx
itkLandweberDeconvolutionImageFilterTest.cxx
itkProjectedIterativeDeconvolutionImageFilterTest.cxx
itkParametricBlindLeastSquaresDeconvolutionImageFilterTest.cxx
itkProjectedLandweberDeconvolutionImageFilterTest.cxx
itkRichardsonLucyDeconvolutionImageFilterTest.cxx
itkTikhonovDeconvolutionImageFilterTest.cxx
itkWienerDeconvolutionImageFilterTest.cxx
itkParametricBlindLeastSquaresDeconvolutionImageFilterTest.cxx
)

createtestdriver(ITKDeconvolution "${ITKDeconvolution-Test_LIBRARIES}" "${ITKDeconvolutionTests}")

set(
ITKDeconvolutionGTests
itkProjectedIterativeDeconvolutionImageFilterGTest.cxx
)

creategoogletestdriver(ITKDeconvolution "${ITKDeconvolution-Test_LIBRARIES}" "${ITKDeconvolutionGTests}")

itk_add_test(
NAME itkRichardsonLucyDeconvolutionImageFilterGaussianKernelTest
COMMAND
Expand Down Expand Up @@ -81,12 +87,6 @@ itk_add_test(
1
2.0
)
itk_add_test(
NAME itkProjectedIterativeDeconvolutionimageFilterTest
COMMAND
ITKDeconvolutionTestDriver
itkProjectedIterativeDeconvolutionImageFilterTest
)
itk_add_test(
NAME itkProjectedLandweberDeconvolutionImageFilterGaussianKernelTest
COMMAND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,16 @@
#include "itkImage.h"
#include "itkLandweberDeconvolutionImageFilter.h"
#include "itkProjectedIterativeDeconvolutionImageFilter.h"
#include "itkSimpleFilterWatcher.h"
#include "itkGTest.h"

int
itkProjectedIterativeDeconvolutionImageFilterTest(int, char *[])
TEST(ProjectedIterativeDeconvolutionImageFilter, BasicObjectMethods)
{
// Declare the image type
using ImageType = itk::Image<float, 2>;

// Declare the base deconvolution filter choice
using BaseDeconvolutionFilterType = itk::LandweberDeconvolutionImageFilter<ImageType>;

// Declare a projected version of the base deconvolution image filter
using ProjectedDeconvolutionFilterType = itk::ProjectedIterativeDeconvolutionImageFilter<BaseDeconvolutionFilterType>;

// Just instantiate the filter and print it
auto deconvolutionFilter = ProjectedDeconvolutionFilterType::New();
deconvolutionFilter->Print(std::cout);

const itk::SimpleFilterWatcher watcher(deconvolutionFilter);

return EXIT_SUCCESS;
ITK_GTEST_EXERCISE_BASIC_OBJECT_METHODS(
deconvolutionFilter, ProjectedIterativeDeconvolutionImageFilter, IterativeDeconvolutionImageFilter);
}
1 change: 1 addition & 0 deletions Modules/Filtering/ImageLabel/itk-module.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ itk_module(
DEPENDS
ITKImageIntensity
TEST_DEPENDS
ITKGoogleTest
ITKTestKernel
DESCRIPTION "${DOCUMENTATION}"
)
13 changes: 5 additions & 8 deletions Modules/Filtering/ImageLabel/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
itk_module_test()
set(
ITKImageLabelTests
itkChangeLabelImageFilterTest.cxx
itkLabelContourImageFilterTest.cxx
itkBinaryContourImageFilterTest.cxx
itkLabelContourImageFilterTest.cxx
)

createtestdriver(ITKImageLabel "${ITKImageLabel-Test_LIBRARIES}" "${ITKImageLabelTests}")

itk_add_test(
NAME itkChangeLabelImageFilterTest
COMMAND
ITKImageLabelTestDriver
itkChangeLabelImageFilterTest
)
set(ITKImageLabelGTests itkChangeLabelImageFilterGTest.cxx)

creategoogletestdriver(ITKImageLabel "${ITKImageLabel-Test_LIBRARIES}" "${ITKImageLabelGTests}")

itk_add_test(
NAME itkLabelContourImageFilterTest0
COMMAND
Expand Down
112 changes: 112 additions & 0 deletions Modules/Filtering/ImageLabel/test/itkChangeLabelImageFilterGTest.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*=========================================================================
*
* 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.
*
*=========================================================================*/

#include "itkRandomImageSource.h"
#include "itkChangeLabelImageFilter.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "itkGTest.h"

TEST(ChangeLabelImageFilter, FilterLabelsAboveThreshold)
{
constexpr unsigned int ImageDimension{ 3 };

using InputImageType = itk::Image<unsigned short, ImageDimension>;
using OutputImageType = itk::Image<unsigned char, ImageDimension>;
using InputPixelType = InputImageType::PixelType;

using SourceType = itk::RandomImageSource<InputImageType>;
auto source = SourceType::New();

InputImageType::SizeValueType sizeArray[ImageDimension] = { 3, 3, 3 };

constexpr InputPixelType upper{ 10 };
source->SetMin(InputPixelType{});
source->SetMax(upper);
source->SetSize(sizeArray);

using FilterType = itk::ChangeLabelImageFilter<InputImageType, OutputImageType>;
auto filter = FilterType::New();

ITK_GTEST_EXERCISE_BASIC_OBJECT_METHODS(filter, ChangeLabelImageFilter, UnaryFunctorImageFilter);

constexpr InputPixelType background{ 0 };
constexpr InputPixelType maxRemainingLabel{ 2 };
for (InputPixelType i = maxRemainingLabel; i <= upper; ++i)
{
filter->SetChange(i, background);
}

filter->SetInput(source->GetOutput());

EXPECT_NO_THROW(filter->Update());
filter->SetFunctor(filter->GetFunctor());

const auto outputImage = filter->GetOutput();

itk::ImageRegionIteratorWithIndex<OutputImageType> ot(outputImage, outputImage->GetRequestedRegion());
for (ot.GoToBegin(); !ot.IsAtEnd(); ++ot)
{
EXPECT_LE(ot.Get(), maxRemainingLabel);
}
}

TEST(ChangeLabelImageFilter, ClearChangeMapPassesThrough)
{
constexpr unsigned int ImageDimension{ 3 };

using InputImageType = itk::Image<unsigned short, ImageDimension>;
using OutputImageType = itk::Image<unsigned char, ImageDimension>;
using InputPixelType = InputImageType::PixelType;

using SourceType = itk::RandomImageSource<InputImageType>;
auto source = SourceType::New();

InputImageType::SizeValueType sizeArray[ImageDimension] = { 3, 3, 3 };

constexpr InputPixelType upper{ 10 };
source->SetMin(InputPixelType{});
source->SetMax(upper);
source->SetSize(sizeArray);

using FilterType = itk::ChangeLabelImageFilter<InputImageType, OutputImageType>;
auto filter = FilterType::New();

constexpr InputPixelType background{ 0 };
constexpr InputPixelType maxRemainingLabel{ 2 };
for (InputPixelType i = maxRemainingLabel; i <= upper; ++i)
{
filter->SetChange(i, background);
}

filter->SetInput(source->GetOutput());
filter->Update();

// Clear the change map so input passes through unchanged
filter->ClearChangeMap();

EXPECT_NO_THROW(filter->Update());

const auto outputImage = filter->GetOutput();

itk::ImageRegionIteratorWithIndex<InputImageType> it(source->GetOutput(), source->GetOutput()->GetRequestedRegion());
itk::ImageRegionIteratorWithIndex<OutputImageType> ot(outputImage, outputImage->GetRequestedRegion());
for (it.GoToBegin(), ot.GoToBegin(); !ot.IsAtEnd(); ++it, ++ot)
{
EXPECT_EQ(it.Get(), ot.Get());
}
}
Loading
Loading