ITK  4.8.0
Insight Segmentation and Registration Toolkit
SphinxExamples/src/Filtering/ImageGradient/ComputeGradientMagnitude/Code.cxx
#include "itkImage.h"
int main(int argc, char * argv[])
{
// Verify command line arguments
if( argc != 3 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " <InputImage> <OutputImage" << std::endl;
return EXIT_FAILURE;
}
const char * inputFileName = argv[1];
const char * outputFileName = argv[2];
const unsigned int Dimension = 2;
typedef unsigned char InputPixelType;
typedef float OutputPixelType;
// Create and setup a reader
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( inputFileName );
// Create and setup a gradient filter
InputImageType, OutputImageType > FilterType;
FilterType::Pointer gradientFilter = FilterType::New();
gradientFilter->SetInput( reader->GetOutput() );
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( outputFileName );
writer->SetInput( gradientFilter->GetOutput() );
try
{
writer->Update();
}
catch( itk::ExceptionObject & error )
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}