Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N4 verbosity #978

Closed
wants to merge 1 commit into from
Closed
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
46 changes: 39 additions & 7 deletions Examples/N4BiasFieldCorrection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,44 @@ int N4( itk::ants::CommandLineParser *parser )
{
using RealType = float;

using ImageType = itk::Image<RealType, ImageDimension>;
typename ImageType::Pointer inputImage = nullptr;

using MaskImageType = itk::Image<RealType, ImageDimension>;
typename MaskImageType::Pointer maskImage = nullptr;

bool verbose = false;
typename itk::ants::CommandLineParser::OptionType::Pointer verboseOption =
parser->GetOption( "verbose" );
if( verboseOption && verboseOption->GetNumberOfFunctions() )
{
verbose = parser->Convert<bool>( verboseOption->GetFunction( 0 )->GetName() );
}
if( verbose )
{
std::cout << std::endl << "Creating ImageType" << std::endl;
}
using ImageType = itk::Image<RealType, ImageDimension>;
typename ImageType::Pointer inputImage = nullptr;

if( verbose )
{
std::cout << std::endl << "Creating MaskImageType" << std::endl;
}
using MaskImageType = itk::Image<RealType, ImageDimension>;
typename MaskImageType::Pointer maskImage = nullptr;

if( verbose )
{
std::cout << std::endl << "Running N4 for "
<< ImageDimension << "-dimensional images." << std::endl << std::endl;
}

if( verbose )
{
std::cout << std::endl << "Getting CorrecterType" << std::endl;
}
using CorrecterType = itk::N4BiasFieldCorrectionImageFilter<ImageType, MaskImageType, ImageType>;
typename CorrecterType::Pointer correcter = CorrecterType::New();

if( verbose )
{
std::cout << std::endl << "Reading in Input Image" << std::endl;
}
typename itk::ants::CommandLineParser::OptionType::Pointer inputImageOption =
parser->GetOption( "input-image" );
if( inputImageOption && inputImageOption->GetNumberOfFunctions() )
Expand All @@ -117,9 +133,17 @@ int N4( itk::ants::CommandLineParser *parser )

typename itk::ants::CommandLineParser::OptionType::Pointer maskImageOption =
parser->GetOption( "mask-image" );
if( maskImageOption && maskImageOption->GetNumberOfFunctions() )
if( verbose )
{
std::cout << std::endl << "maskImageOption: " << maskImageOption << std::endl;
}
if( maskImageOption && maskImageOption->GetNumberOfFunctions() )
{
std::string inputMaskFile = maskImageOption->GetFunction( 0 )->GetName();
if( verbose )
{
std::cout << std::endl << "Reading in Mask file: " << inputMaskFile << std::endl;
}
ReadImage<MaskImageType>( maskImage, inputMaskFile.c_str() );

isMaskImageSpecified = true;
Expand All @@ -140,6 +164,10 @@ int N4( itk::ants::CommandLineParser *parser )
/**
* check for negative values in the masked region
*/
if( verbose )
{
std::cout << std::endl << "Checking for Negative Values" << std::endl;
}
using ThresholderType = itk::BinaryThresholdImageFilter<MaskImageType, MaskImageType>;
typename ThresholderType::Pointer thresholder = ThresholderType::New();
thresholder->SetInsideValue( itk::NumericTraits<typename MaskImageType::PixelType>::ZeroValue() );
Expand All @@ -148,6 +176,10 @@ int N4( itk::ants::CommandLineParser *parser )
thresholder->SetUpperThreshold( itk::NumericTraits<typename MaskImageType::PixelType>::ZeroValue() );
thresholder->SetInput( maskImage );

if( verbose )
{
std::cout << std::endl << "Running LabelStatisticsImageFilter" << std::endl;
}
using StatsType = itk::LabelStatisticsImageFilter<ImageType, MaskImageType>;
typename StatsType::Pointer statsOriginal = StatsType::New();
statsOriginal->SetInput( inputImage );
Expand Down