ITK/Examples/VectorImages/VectorMagnitudeImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Write the result.)
(Deprecated content that is moved to sphinxe)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==VectorMagnitudeImageFilter.cxx==
{{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/*  pages likely require ITK version 4.13 or earlier releases.   In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.
<source lang="cpp">
}}
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkVectorImage.h"
#include "itkVectorMagnitudeImageFilter.h"
 
int main(int argc, char * argv[])
{
  // Verify command line arguments
  if( argc < 3 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " inputImageFile outputImageFile" << std::endl;
    return EXIT_FAILURE;
    }
 
  // Parse command line arguments
  std::string inputFilename = argv[1];
  std::string outputFilename = argv[2];
 
  // Setup types
  typedef itk::VectorImage< float, 2 >    VectorImageType;
  typedef itk::Image< unsigned char, 2 >  UnsignedCharImageType;
 
  typedef itk::ImageFileReader< VectorImageType >  ReaderType;
  typedef itk::ImageFileWriter< UnsignedCharImageType >  WriterType;
 
  typedef itk::VectorMagnitudeImageFilter<
    VectorImageType, UnsignedCharImageType >  VectorMagnitudeFilterType;
 
  // Create and setup a reader
  ReaderType::Pointer reader =
    ReaderType::New();
  reader->SetFileName( inputFilename );
 
  // Create and setup a gradient filter
  VectorMagnitudeFilterType::Pointer magnitudeFilter =
    VectorMagnitudeFilterType::New();
  magnitudeFilter->SetInput( reader->GetOutput() );
 
   // To write the magnitude image file, we should rescale the gradient values
  // to a reasonable range
  typedef itk::RescaleIntensityImageFilter<
    UnsignedCharImageType, UnsignedCharImageType > rescaleFilterType;
 
  rescaleFilterType::Pointer rescaler =
    rescaleFilterType::New();
  rescaler->SetOutputMinimum(0);
  rescaler->SetOutputMaximum(255);
  rescaler->SetInput( magnitudeFilter->GetOutput() );
 
  WriterType::Pointer writer =
    WriterType::New();
 
  writer->SetFileName( outputFilename );
  writer->SetInput( rescaler->GetOutput() );
  writer->Update();
 
  return EXIT_SUCCESS;
}
</source>
 
{{ITKCMakeLists|VectorMagnitudeImageFilter}}

Latest revision as of 21:00, 5 June 2019

Warning: The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.