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
@@ -0,0 +1 @@
33266a4cb8171925d5c606eec70080d0918ae6077103e37cda499fa5194a865a68ff094fa1ebb127413973838cd6702df7a8d10005ba1283f4bec7a6c9e6b92d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9d23f748390540c7f7af23c47ffcb02547620454d755f828fce723fddaa79044b7721ad3fc94b022b5bdac07c8d13ea0c6a9fdb8f6faec89c8f0300f673f8b7a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9d23f748390540c7f7af23c47ffcb02547620454d755f828fce723fddaa79044b7721ad3fc94b022b5bdac07c8d13ea0c6a9fdb8f6faec89c8f0300f673f8b7a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
107e34c5ff0d55e8277378dc0d7fe75c14599fc7c191ce4f955aff10ebbd597627e5669fb044267510c200a8bc546ed6a65a3134961e75832476cdfde00f2003
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f8bca7784b541e48d73fef396c69fc6b
b30b1166f9b42b910e3561df16922778

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
c97875180340d5c10f328531ffc77b04
403a1256fdc1a7804bd15d8336073bf0

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
75a3a4393ec6c81a5186f8d05e00eea6592a4f783f3154cb016cbdbd7d3418f9868b60ba64f7c91d171c2f60b9f9b7ff375ee6155bec165846742ba0754bc30a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
75a3a4393ec6c81a5186f8d05e00eea6592a4f783f3154cb016cbdbd7d3418f9868b60ba64f7c91d171c2f60b9f9b7ff375ee6155bec165846742ba0754bc30a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d67efb2b404c982c30b72a43c6b92ce0d8f23e4ee174cac1af6f37cdb320e752e47ed0a1281b56af040d2f3150c053ddf2b1474816c0716e8b84571deff72d8d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d67efb2b404c982c30b72a43c6b92ce0d8f23e4ee174cac1af6f37cdb320e752e47ed0a1281b56af040d2f3150c053ddf2b1474816c0716e8b84571deff72d8d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7d3ccf81cb874c81e2dcb1c476fae832fe9664e8095a116cb254dbc5a073d2f481abe3745976fc7ca8089db73b70133cb1d6b7d3cc447284be6ca68b497266ab
Original file line number Diff line number Diff line change
@@ -1 +1 @@
679279da24b82874797d62965e50270e
f932df866e06bdc783b2617d39011e3a

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d21c829dcac3e13d264a20d355b02a87
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d67efb2b404c982c30b72a43c6b92ce0d8f23e4ee174cac1af6f37cdb320e752e47ed0a1281b56af040d2f3150c053ddf2b1474816c0716e8b84571deff72d8d

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
eaff57ba1e732e62112bb46ed1ce4a546f5eefc56ad8fc56c1a9cec3a3c1b413d1919231723022dd8e70aefb2af18586b86c19886a13d24029ddd821742ef0a4
2b3848a33d1407cfc8ffa5d71bd69596b76c2819c8fc14bba8e21a3793e0fefd34910540852425a329483f191a7079c0855928a7607ad178bb50d5f1a9447dd1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f3ae5b75b0172f96fc3a9c74ed4dd98934825e2587ee3908d52d034a28288c33d8b08d08012883cc41fc330dbe1542d6f49db8322c0dc5d4f84a23a0a3c27877
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d67efb2b404c982c30b72a43c6b92ce0d8f23e4ee174cac1af6f37cdb320e752e47ed0a1281b56af040d2f3150c053ddf2b1474816c0716e8b84571deff72d8d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
75a3a4393ec6c81a5186f8d05e00eea6592a4f783f3154cb016cbdbd7d3418f9868b60ba64f7c91d171c2f60b9f9b7ff375ee6155bec165846742ba0754bc30a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d67efb2b404c982c30b72a43c6b92ce0d8f23e4ee174cac1af6f37cdb320e752e47ed0a1281b56af040d2f3150c053ddf2b1474816c0716e8b84571deff72d8d
173 changes: 123 additions & 50 deletions Modules/Filtering/Thresholding/test/CMakeLists.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@

#include "itkRandomImageSource.h"
#include "itkBinaryThresholdImageFilter.h"
#include "itkNumericTraits.h"
#include "itkMath.h"
#include "itkTestingMacros.h"


int
itkBinaryThresholdImageFilterTest(int, char *[])
{

// Define the dimension of the images
constexpr unsigned int ImageDimension = 3;
constexpr unsigned int Dimension = 3;

using InputPixelType = unsigned char;
using OutputPixelType = float;

// Declare the types of the images
using InputImageType = itk::Image<unsigned char, ImageDimension>;
using OutputImageType = itk::Image<float, ImageDimension>;
using InputPixelType = InputImageType::PixelType;
using OutputPixelType = OutputImageType::PixelType;
using InputImageType = itk::Image<InputPixelType, Dimension>;
using OutputImageType = itk::Image<OutputPixelType, Dimension>;

// Declare iterator type
using InputIteratorType = itk::ImageRegionIteratorWithIndex<InputImageType>;
Expand All @@ -43,7 +45,7 @@ itkBinaryThresholdImageFilterTest(int, char *[])
using SourceType = itk::RandomImageSource<InputImageType>;
SourceType::Pointer source = SourceType::New();

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

source->SetMin(itk::NumericTraits<InputPixelType>::ZeroValue());
source->SetMax(itk::NumericTraits<InputPixelType>::max());
Expand All @@ -52,124 +54,154 @@ itkBinaryThresholdImageFilterTest(int, char *[])
// Declare the type for the binary threshold filter
using FilterType = itk::BinaryThresholdImageFilter<InputImageType, OutputImageType>;


// Create a filter
FilterType::Pointer filter = FilterType::New();

// Setup ivars
ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, BinaryThresholdImageFilter, UnaryFunctorImageFilter);

// Set up ivars
InputPixelType lower = 64;
InputPixelType upper = 128;
filter->SetUpperThreshold(upper);
filter->SetLowerThreshold(lower);

OutputPixelType inside = -0.5;
OutputPixelType outside = 0.5;
filter->SetInsideValue(inside);
filter->SetOutsideValue(outside);

filter->Print(std::cout);
// No input set: check that thresholds are created using the input
// pixel type non-positive min value
//

filter->SetFunctor(filter->GetFunctor());
// Lower threshold
FilterType::InputPixelObjectType::Pointer lowerThreshold1 = filter->GetLowerThresholdInput();

// exercise Get methods
std::cout << "OutsideValue: " << filter->GetOutsideValue() << std::endl;
std::cout << "InsideValue: " << filter->GetInsideValue() << std::endl;
std::cout << "UpperThreshold: " << itk::NumericTraits<InputPixelType>::PrintType(filter->GetUpperThreshold())
<< std::endl;
std::cout << "LowerThreshold: " << itk::NumericTraits<InputPixelType>::PrintType(filter->GetLowerThreshold())
<< std::endl;
if (lowerThreshold1->Get() != itk::NumericTraits<InputPixelType>::NonpositiveMin())
{
std::cerr << "Test failed!" << std::endl;
std::cerr << "Error in GetLowerThresholdInput():" << std::endl;
std::cerr << "Expected: "
<< static_cast<itk::NumericTraits<OutputPixelType>::PrintType>(
itk::NumericTraits<InputPixelType>::NonpositiveMin())
<< ", but got: " << static_cast<itk::NumericTraits<OutputPixelType>::PrintType>(lowerThreshold1->Get())
<< std::endl;
return EXIT_FAILURE;
}

// Connect the input images
filter->SetInput(source->GetOutput());
FilterType::InputPixelObjectType::Pointer lowerThreshold2 = FilterType::InputPixelObjectType::New();
filter->SetLowerThresholdInput(lowerThreshold2);

// Get the Smart Pointer to the Filter Output
OutputImageType::Pointer outputImage = filter->GetOutput();
if (lowerThreshold2->Get() != itk::NumericTraits<InputPixelType>::NonpositiveMin())
{
std::cerr << "Test failed!" << std::endl;
std::cerr << "Error in GetLowerThresholdInput():" << std::endl;
std::cerr << "Expected: "
<< static_cast<itk::NumericTraits<OutputPixelType>::PrintType>(
itk::NumericTraits<InputPixelType>::NonpositiveMin())
<< ", but got: " << static_cast<itk::NumericTraits<OutputPixelType>::PrintType>(lowerThreshold2->Get())
<< std::endl;
return EXIT_FAILURE;
}

// Upper threshold
FilterType::InputPixelObjectType::Pointer upperThreshold1 = filter->GetUpperThresholdInput();

// Execute the filter
try
if (lowerThreshold1->Get() != itk::NumericTraits<InputPixelType>::NonpositiveMin())
{
filter->Update();
filter->SetFunctor(filter->GetFunctor());
std::cerr << "Test failed!" << std::endl;
std::cerr << "Error in GetUpperThresholdInput():" << std::endl;
std::cerr << "Expected: "
<< static_cast<itk::NumericTraits<OutputPixelType>::PrintType>(
itk::NumericTraits<InputPixelType>::NonpositiveMin())
<< ", but got: " << static_cast<itk::NumericTraits<OutputPixelType>::PrintType>(upperThreshold1->Get())
<< std::endl;
return EXIT_FAILURE;
}

catch (...)
FilterType::InputPixelObjectType::Pointer upperThreshold2 = FilterType::InputPixelObjectType::New();
filter->SetUpperThresholdInput(upperThreshold2);

if (upperThreshold2->Get() != itk::NumericTraits<InputPixelType>::NonpositiveMin())
{
std::cerr << "Caught an unexpected exception. " << std::endl;
std::cerr << "Test failed. " << std::endl;
std::cerr << "Test failed!" << std::endl;
std::cerr << "Error in GetLowerThresholdInput():" << std::endl;
std::cerr << "Expected: "
<< static_cast<itk::NumericTraits<OutputPixelType>::PrintType>(
itk::NumericTraits<InputPixelType>::NonpositiveMin())
<< ", but got: " << static_cast<itk::NumericTraits<OutputPixelType>::PrintType>(upperThreshold2->Get())
<< std::endl;
return EXIT_FAILURE;
}


// Deliberately cause an exception by setting lower threshold to be
// greater than the upper threshold
filter->SetLowerThreshold(upper);
filter->SetUpperThreshold(lower);

ITK_TRY_EXPECT_EXCEPTION(filter->Update());


filter->SetLowerThreshold(lower);
ITK_TEST_SET_GET_VALUE(lower, filter->GetLowerThreshold());

filter->SetUpperThreshold(upper);
ITK_TEST_SET_GET_VALUE(upper, filter->GetUpperThreshold());

OutputPixelType inside = -0.5;
filter->SetInsideValue(inside);
ITK_TEST_SET_GET_VALUE(inside, filter->GetInsideValue());

OutputPixelType outside = 0.5;
filter->SetOutsideValue(outside);
ITK_TEST_SET_GET_VALUE(outside, filter->GetOutsideValue());


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

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


ITK_TRY_EXPECT_NO_EXCEPTION(filter->Update());

// Get the filter output
OutputImageType::Pointer outputImage = filter->GetOutput();

// Create an iterator for going through the image output
InputIteratorType it(source->GetOutput(), source->GetOutput()->GetRequestedRegion());
OutputIteratorType ot(outputImage, outputImage->GetRequestedRegion());

// Check the content of the result image
std::cout << "Verification of the output " << std::endl;
// Check the content of the result image
ot.GoToBegin();
it.GoToBegin();
while (!ot.IsAtEnd())
{

const InputPixelType input = it.Get();
const OutputPixelType output = ot.Get();
std::cout << (double)input << " " << (double)output << std::endl;

bool pass = true;
if (lower <= input && input <= upper)
{
if (itk::Math::NotExactlyEquals(output, inside))
{
pass = false;
std::cerr << "Test failed!" << std::endl;
std::cerr << "Error checking the inside value:" << std::endl;
std::cout << "Lower threshold: " << static_cast<itk::NumericTraits<InputPixelType>::PrintType>(lower)
<< ", upper threshold: " << static_cast<itk::NumericTraits<InputPixelType>::PrintType>(upper)
<< std::endl;
std::cerr << "Expected: " << static_cast<itk::NumericTraits<OutputPixelType>::PrintType>(inside)
<< ", but got: " << static_cast<itk::NumericTraits<OutputPixelType>::PrintType>(output) << std::endl;
return EXIT_FAILURE;
}
}
else if (itk::Math::NotExactlyEquals(output, outside))
{
pass = false;
}

if (!pass)
{
std::cerr << "Error in itkBinaryThresholdImageFilterTest " << std::endl;
std::cerr << " lower = " << (double)lower;
std::cerr << " upper = " << (double)upper;
std::cerr << " inside = " << (double)inside;
std::cerr << " outside = " << (double)outside;
std::cerr << std::endl;
std::cerr << " input = " << (double)input;
std::cerr << " output = " << (double)output;
std::cerr << std::endl;
std::cerr << "Test failed!" << std::endl;
std::cerr << "Error checkint the outside value:" << std::endl;
std::cout << "Lower threshold: " << static_cast<itk::NumericTraits<InputPixelType>::PrintType>(lower)
<< ", upper threshold: " << static_cast<itk::NumericTraits<InputPixelType>::PrintType>(upper)
<< std::endl;
std::cerr << "Expected: " << static_cast<itk::NumericTraits<OutputPixelType>::PrintType>(outside)
<< ", but got: " << static_cast<itk::NumericTraits<OutputPixelType>::PrintType>(output) << std::endl;
return EXIT_FAILURE;
}

++ot;
++it;
}


// Deliberately cause an exception by setting lower threshold to be
// greater than the upper threshold
filter->SetUpperThreshold(lower);
filter->SetLowerThreshold(upper);
bool pass = false;
try
{
filter->Update();
}
catch (const itk::ExceptionObject & err)
{
pass = true;
std::cout << "Caught an expected exception. " << std::endl;
std::cout << err << std::endl;
}

if (pass)
{
std::cout << "Test passsed. " << std::endl;
return EXIT_SUCCESS;
}
else
{
std::cout << "Test failed. " << std::endl;
return EXIT_FAILURE;
}
std::cout << "Test finished" << std::endl;
return EXIT_SUCCESS;
}
Loading