int
main(int argc, char * argv[])
{
if (argc < 3)
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImageFile outputImageFile" << std::endl;
return EXIT_FAILURE;
}
const std::string inputImageFile = argv[1];
const std::string outputImageFile = argv[2];
auto reader = ImageReaderType::New();
reader->SetFileName(inputImageFile);
using GradientMagnitudeImageFilter =
itk::VectorGradientMagnitudeImageFilter<RGB2DImageType>;
auto grad = GradientMagnitudeImageFilter::New();
grad->SetInput(reader->GetOutput());
grad->UseImageSpacingOn();
using GradientMagnitudeOutputImageType =
GradientMagnitudeImageFilter::OutputImageType;
using ComposeRGBFilterType =
auto composeRGB = ComposeRGBFilterType::New();
composeRGB->SetInput1(grad->GetOutput());
composeRGB->SetInput2(grad->GetOutput());
composeRGB->SetInput3(grad->GetOutput());
composeRGB->UpdateOutputInformation();
const RGB2DImageType::RegionType largest =
composeRGB->GetOutput()->GetLargestPossibleRegion();
largest.GetIndex(0) +
static_cast<unsigned long>(0.25 * largest.GetSize(0)));
largest.GetIndex(1) +
static_cast<unsigned long>(0.25 * largest.GetSize(1)));
halfIO.
SetSize(0,
static_cast<unsigned long>(0.5 * largest.GetSize(0)));
halfIO.
SetSize(1,
static_cast<unsigned long>(0.5 * largest.GetSize(1)));
using ToVectorImageAdaptorType =
auto adaptor = ToVectorImageAdaptorType::New();
adaptor->SetImage(composeRGB->GetOutput());
auto writer = ImageWriterType::New();
writer->SetFileName(outputImageFile);
writer->SetNumberOfStreamDivisions(10);
writer->SetIORegion(halfIO);
writer->SetInput(adaptor);
try
{
writer->Update();
}
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
ComposeImageFilter combine several scalar images into a multicomponent image.
Standard exception handling object.
Data source that reads image data from a single file.
Writes image data to a single file.
An ImageIORegion represents a structured region of data.
void SetIndex(const IndexType &index)
void SetSize(const SizeType &size)
Templated n-dimensional image class.
Represent Red, Green and Blue components for color images.
Presents an image of pixel type RGBPixel as being and image of Vectors.
Simple mechanism for monitoring the pipeline events of a filter and reporting these events to std::co...