Skip to content
Closed
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 @@ -128,7 +128,7 @@ N4(int argc, char * argv[])
ImagePointer inputImage = reader->GetOutput();
inputImage->DisconnectPipeline();

// handle the mask image
// Handle the mask image
Comment thread
jhlegarreta marked this conversation as resolved.
using MaskImageType = itk::Image<unsigned char, ImageDimension>;
typename MaskImageType::Pointer maskImage = nullptr;

Expand Down Expand Up @@ -164,15 +164,44 @@ N4(int argc, char * argv[])
maskImage->DisconnectPipeline();
}

// instantiate N4 and assign variables not exposed to the user in this test.
// Instantiate N4 and assign variables not exposed to the user in this test.
using CorrecterType = itk::N4BiasFieldCorrectionImageFilter<ImageType, MaskImageType, ImageType>;
typename CorrecterType::Pointer correcter = CorrecterType::New();
correcter->SetSplineOrder(3);

ITK_EXERCISE_BASIC_OBJECT_METHODS(correcter, N4BiasFieldCorrectionImageFilter, ImageToImageFilter);


unsigned int splineOrder = 3;
correcter->SetSplineOrder(splineOrder);
ITK_TEST_SET_GET_VALUE(splineOrder, correcter->GetSplineOrder());

correcter->SetWienerFilterNoise(0.01);
correcter->SetBiasFieldFullWidthAtHalfMaximum(0.15);
correcter->SetConvergenceThreshold(0.0000001);

// handle the number of iterations
typename CorrecterType::RealType biasFieldFullWidthAtHalfMaximum = 0.15;
correcter->SetBiasFieldFullWidthAtHalfMaximum(biasFieldFullWidthAtHalfMaximum);
ITK_TEST_SET_GET_VALUE(biasFieldFullWidthAtHalfMaximum, correcter->GetBiasFieldFullWidthAtHalfMaximum());

typename CorrecterType::RealType convergenceThreshold = 0.0000001;
correcter->SetConvergenceThreshold(convergenceThreshold);
ITK_TEST_SET_GET_VALUE(convergenceThreshold, correcter->GetConvergenceThreshold());

unsigned int numberOfHistogramBins = 200;
correcter->SetNumberOfHistogramBins(numberOfHistogramBins);
ITK_TEST_SET_GET_VALUE(numberOfHistogramBins, correcter->GetNumberOfHistogramBins());

typename CorrecterType::RealType wienerFilterNoise = 0.01;
correcter->SetWienerFilterNoise(wienerFilterNoise);
ITK_TEST_SET_GET_VALUE(wienerFilterNoise, correcter->GetWienerFilterNoise());

typename CorrecterType::MaskPixelType maskLabel =
itk::NumericTraits<typename CorrecterType::MaskPixelType>::OneValue();
correcter->SetMaskLabel(maskLabel);
ITK_TEST_SET_GET_VALUE(maskLabel, correcter->GetMaskLabel());

bool useMaskLabel = false;
ITK_TEST_SET_GET_BOOLEAN(correcter, UseMaskLabel, useMaskLabel);

// Handle the number of iterations
std::vector<unsigned int> numIters = ConvertVector<unsigned int>(std::string("100x50x50"));
if (argc > 5)
{
Expand All @@ -185,17 +214,18 @@ N4(int argc, char * argv[])
maximumNumberOfIterations[d] = numIters[d];
}
correcter->SetMaximumNumberOfIterations(maximumNumberOfIterations);
ITK_TEST_SET_GET_VALUE(maximumNumberOfIterations, correcter->GetMaximumNumberOfIterations());

typename CorrecterType::ArrayType numberOfFittingLevels;
numberOfFittingLevels.Fill(
static_cast<typename CorrecterType::VariableSizeArrayType::SizeValueType>(numIters.size()));
correcter->SetNumberOfFittingLevels(numberOfFittingLevels);
ITK_TEST_SET_GET_VALUE(numberOfFittingLevels, correcter->GetNumberOfFittingLevels());

/* B-spline options -- we place this here to take care of the case where
* the user wants to specify things in terms of the spline distance.
* 1. need to pad the images to get as close to possible to the
* requested domain size.
*/
// B-spline options -- we place this here to take care of the case where
// the user wants to specify things in terms of the spline distance.
// 1. need to pad the images to get as close to possible to the
// requested domain size.
typename ImageType::PointType newOrigin = inputImage->GetOrigin();

typename CorrecterType::ArrayType numberOfControlPoints;
Expand Down Expand Up @@ -245,8 +275,9 @@ N4(int argc, char * argv[])
maskImage->DisconnectPipeline();

correcter->SetNumberOfControlPoints(numberOfControlPoints);
ITK_TEST_SET_GET_VALUE(numberOfControlPoints, correcter->GetNumberOfControlPoints());

// handle the shrink factor
// Handle the shrink factor
using ShrinkerType = itk::ShrinkImageFilter<ImageType, ImageType>;
typename ShrinkerType::Pointer shrinker = ShrinkerType::New();
shrinker->SetInput(inputImage);
Expand All @@ -270,26 +301,16 @@ N4(int argc, char * argv[])
maskImage = maskshrinker->GetOutput();
maskImage->DisconnectPipeline();

// set the input image and mask image
// Set the input image and mask image
correcter->SetInput(inputImage);
correcter->SetMaskImage(maskImage);

using CommandType = CommandIterationUpdate<CorrecterType>;
typename CommandType::Pointer observer = CommandType::New();
correcter->AddObserver(itk::IterationEvent(), observer);

try
{
correcter->Update();
}
catch (const itk::ExceptionObject & excep)
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
return EXIT_FAILURE;
}
ITK_TRY_EXPECT_NO_EXCEPTION(correcter->Update());

correcter->Print(std::cout, 3);

// Test the reconstruction of the log bias field
ImagePointer originalInputImage = reader->GetOutput();
Expand All @@ -300,7 +321,7 @@ N4(int argc, char * argv[])
correcter->ReconstructBiasField(correcter->GetLogBiasFieldControlPointLattice());
WriteImage(biasField.GetPointer(), (std::string(argv[3]) + "-LogBiasField.nrrd").c_str());

// output the log bias field control point lattice
// Output the log bias field control point lattice
WriteImage(correcter->GetLogBiasFieldControlPointLattice(), argv[3]);

return EXIT_SUCCESS;
Expand All @@ -315,7 +336,7 @@ itkN4BiasFieldCorrectionImageFilterTest(int argc, char * argv[])
<< "outputLogControlPointLattice [shrinkFactor,default=1] "
<< "[numberOfIterations,default=100x50x50] "
<< " [maskImageWithLabelEqualTo1] [splineDistance,default=200]" << std::endl;
exit(EXIT_FAILURE);
return EXIT_FAILURE;
}

switch (std::stoi(argv[1]))
Expand All @@ -328,6 +349,6 @@ itkN4BiasFieldCorrectionImageFilterTest(int argc, char * argv[])

default:
std::cerr << "Unsupported dimension" << std::endl;
exit(EXIT_FAILURE);
return EXIT_FAILURE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,61 @@ int
itkBinaryClosingByReconstructionImageFilterTest(int argc, char * argv[])
{

if (argc != 6)
if (argc < 6)
Comment thread
jhlegarreta marked this conversation as resolved.
{
std::cerr << "usage: " << itkNameOfTestExecutableMacro(argv) << " input output conn fg kernelSize" << std::endl;
// std::cerr << " : " << std::endl;
exit(1);
std::cerr << "Missing Parameters." << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv)
<< " inputFileName outputFileName fullyConnected foregroundValue kernelSize" << std::endl;
return EXIT_FAILURE;
}

constexpr int dim = 2;
constexpr unsigned int Dimension = 2;

using IType = itk::Image<unsigned char, dim>;
using PixelType = unsigned char;

using ReaderType = itk::ImageFileReader<IType>;
using ImageType = itk::Image<PixelType, Dimension>;

using ReaderType = itk::ImageFileReader<ImageType>;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
reader->Update();

using KernelType = itk::BinaryBallStructuringElement<bool, dim>;
ITK_TRY_EXPECT_NO_EXCEPTION(reader->Update());


using KernelType = itk::BinaryBallStructuringElement<bool, Dimension>;
KernelType ball;
KernelType::SizeType ballSize;
ballSize.Fill(std::stoi(argv[5]));
ball.SetRadius(ballSize);
ball.CreateStructuringElement();

using I2LType = itk::BinaryClosingByReconstructionImageFilter<IType, KernelType>;
I2LType::Pointer reconstruction = I2LType::New();
reconstruction->SetInput(reader->GetOutput());
reconstruction->SetKernel(ball);
reconstruction->SetFullyConnected(std::stoi(argv[3]));
reconstruction->SetForegroundValue(std::stoi(argv[4]));
// reconstruction->SetBackgroundValue( std::stoi(argv[6]) );
itk::SimpleFilterWatcher watcher(reconstruction, "filter");
using FilterType = itk::BinaryClosingByReconstructionImageFilter<ImageType, KernelType>;
FilterType::Pointer reconstructionFilter = FilterType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(reconstructionFilter, BinaryClosingByReconstructionImageFilter, KernelImageFilter);


itk::SimpleFilterWatcher watcher(reconstructionFilter, "filter");

auto fullyConnected = static_cast<bool>(std::stoi(argv[3]));
ITK_TEST_SET_GET_BOOLEAN(reconstructionFilter, FullyConnected, fullyConnected);

using WriterType = itk::ImageFileWriter<IType>;
typename FilterType::InputImagePixelType foregroundValue = std::stoi(argv[4]);
reconstructionFilter->SetForegroundValue(foregroundValue);
ITK_TEST_SET_GET_VALUE(foregroundValue, reconstructionFilter->GetForegroundValue());

reconstructionFilter->SetKernel(ball);

reconstructionFilter->SetInput(reader->GetOutput());

using WriterType = itk::ImageFileWriter<ImageType>;
WriterType::Pointer writer = WriterType::New();
writer->SetInput(reconstruction->GetOutput());
writer->SetInput(reconstructionFilter->GetOutput());
writer->SetFileName(argv[2]);
writer->Update();
return 0;

ITK_TRY_EXPECT_NO_EXCEPTION(writer->Update());


std::cout << "Test finished." << std::endl;
return EXIT_SUCCESS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ namespace itk
* itk::Image<TRealType, N>.
*
* \par Filter Parameters
* The method SetUseImageSpacingOn will cause derivatives in the image to be
* The method UseImageSpacingOn will cause derivatives in the image to be
Comment thread
jhlegarreta marked this conversation as resolved.
* scaled (inversely) with the pixel size of the input image, effectively
* taking derivatives in world coordinates (versus isotropic image
* space). SetUseImageSpacingOff turns this functionality off. Default is
* space). UseImageSpacingOff turns this functionality off. Default is
* UseImageSpacingOn. The parameter UseImageSpacing can
* be set directly with the method SetUseImageSpacing(bool).
*
Expand Down Expand Up @@ -170,10 +170,23 @@ class ITK_TEMPLATE_EXPORT DisplacementFieldJacobianDeterminantFilter
void
GenerateInputRequestedRegion() override;

/** Set/Get whether or not the filter will use the spacing of the input
* image (1/spacing) in the calculation of the Jacobian determinant. Use On
* to compute the Jacobian determinant in the space in which the data was
* acquired; use Off to reset the derivative weights, ignore the image
* spacing, and to compute the Jacobian determinant in the image space.
* Default is On. */
void
SetUseImageSpacing(bool);
itkGetConstMacro(UseImageSpacing, bool);
itkBooleanMacro(UseImageSpacing);

#if !defined(ITK_FUTURE_LEGACY_REMOVE)
/** Set the derivative weights according to the spacing of the input image
(1/spacing). Use this option if you want to calculate the Jacobian
determinant in the space in which the data was acquired. Default
is ImageSpacingOn. */
is ImageSpacingOn.
\deprecated Use DisplacementFieldJacobianDeterminantFilter::UseImageSpacingOn instead. */
void
SetUseImageSpacingOn()
{
Expand All @@ -182,19 +195,14 @@ class ITK_TEMPLATE_EXPORT DisplacementFieldJacobianDeterminantFilter

/** Reset the derivative weights to ignore image spacing. Use this option if
you want to calculate the Jacobian determinant in the image space.
Default is ImageSpacingOn. */
Default is ImageSpacingOn.
\deprecated Use DisplacementFieldJacobianDeterminantFilter::UseImageSpacingOff instead. */
void
SetUseImageSpacingOff()
{
this->SetUseImageSpacing(false);
}

/** Set/Get whether or not the filter will use the spacing of the input
image in its calculations */
void
SetUseImageSpacing(bool);

itkGetConstMacro(UseImageSpacing, bool);
#endif

using WeightsType = FixedArray<TRealType, ImageDimension>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "itkCastImageFilter.h"

#include "itkMath.h"
#include "itkMath.h"
#include "itkPrintHelper.h"

namespace itk
{
Expand Down Expand Up @@ -234,25 +234,19 @@ void
DisplacementFieldJacobianDeterminantFilter<TInputImage, TRealType, TOutputImage>::PrintSelf(std::ostream & os,
Indent indent) const
{
unsigned int i;
using namespace print_helper;

Superclass::PrintSelf(os, indent);
os << indent << "m_UseImageSpacing = " << m_UseImageSpacing << std::endl;
os << indent << "m_RequestedNumberOfThreads = " << m_RequestedNumberOfThreads << std::endl;
os << indent << "m_DerivativeWeights = ";
for (i = 0; i < ImageDimension; i++)
{
os << m_DerivativeWeights[i] << " ";
}
os << std::endl;
os << indent << "m_HalfDerivativeWeights = ";
for (i = 0; i < ImageDimension; i++)
{
os << m_HalfDerivativeWeights[i] << " ";
}
os << std::endl;
os << indent << "m_NeighborhoodRadius = " << m_NeighborhoodRadius << std::endl;
os << indent << "m_RealValuedInputImage = " << m_RealValuedInputImage.GetPointer() << std::endl;

os << indent << "DerivativeWeights: " << m_DerivativeWeights << std::endl;
os << indent << "HalfDerivativeWeights: " << m_HalfDerivativeWeights << std::endl;
os << indent << "UseImageSpacing: " << m_UseImageSpacing << std::endl;
os << indent << "RequestedNumberOfThreads: "
<< static_cast<typename NumericTraits<ThreadIdType>::PrintType>(m_RequestedNumberOfThreads) << std::endl;
os << indent << "RealValuedInputImage: " << m_RealValuedInputImage.GetPointer() << std::endl;
os << indent
<< "NeighborhoodRadius: " << static_cast<typename NumericTraits<RadiusType>::PrintType>(m_NeighborhoodRadius)
<< std::endl;
}
} // end namespace itk

Expand Down
2 changes: 1 addition & 1 deletion Modules/Filtering/DisplacementField/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ itk_add_test(NAME itkTransformToDisplacementFieldFilterTest03
--compare ${ITK_TEST_OUTPUT_DIR}/transformedImage.nii
${ITK_TEST_OUTPUT_DIR}/warpedImage.nii
--compareNumberOfPixelsTolerance 20
itkTransformToDisplacementFieldFilterTest1 ${ITK_TEST_OUTPUT_DIR}/transformedImage.nii ${ITK_TEST_OUTPUT_DIR}/warpedImage.nii)
itkTransformToDisplacementFieldFilterTest1 ${ITK_TEST_OUTPUT_DIR}/transformedImage.nii ${ITK_TEST_OUTPUT_DIR}/warpedImage.nii 1)
itk_add_test(NAME itkDisplacementFieldTransformCloneTest
COMMAND ITKDisplacementFieldTestDriver itkDisplacementFieldTransformCloneTest)
itk_add_test(NAME itkExponentialDisplacementFieldImageFilterTest
Expand Down
Loading