ITK/Examples/EdgesAndGradients/GradientMagnitudeImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Created page with "==GradientMagnitudeImageFilter.cxx== <source lang="cpp"> #include <string> #include "itkImage.h" #include "itkImageFileReader.h" #include "itkImageFileWriter.h" #include "itkRes...")
 
(Deprecated content that is moved to sphinx)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==GradientMagnitudeImageFilter.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 <string>


#include "itkImage.h"
[https://itk.org/ITKExamples[ITK Sphinx Examples]]
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkGradientMagnitudeImageFilter.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    float    inputPixelType;
  typedef    float    outputPixelType;
 
  typedef itk::Image< inputPixelType,  2 >  inputImageType;
  typedef itk::Image< outputPixelType, 2 >  outputImageType;
 
  typedef itk::ImageFileReader< inputImageType >  readerType;
 
  typedef itk::GradientMagnitudeImageFilter<
  inputImageType, outputImageType >  filterType;
 
  // Create and setup a reader
  readerType::Pointer reader = readerType::New();
  reader->SetFileName( inputFilename.c_str() );
 
  // Create and setup a gradient filter
  filterType::Pointer gradientFilter = filterType::New();
  gradientFilter->SetInput( reader->GetOutput() );
  gradientFilter->Update();
 
  // To write the gradient image file, we must rescale the gradient values
  // to a reasonable range
  typedef unsigned char writePixelType;
  typedef itk::Image< writePixelType, 2 > writeImageType;
  typedef itk::RescaleIntensityImageFilter<
  outputImageType, writeImageType > rescaleFilterType;
 
  rescaleFilterType::Pointer rescaler = rescaleFilterType::New();
  rescaler->SetOutputMinimum(  0 );
  rescaler->SetOutputMaximum( 255 );
  rescaler->SetInput( gradientFilter->GetOutput() );
 
  // Create and setup a writer
  typedef itk::ImageFileWriter< writeImageType >  writerType;
  writerType::Pointer writer = writerType::New();
  writer->SetFileName( outputFilename.c_str() );
  writer->SetInput( rescaler->GetOutput() );
  writer->Update();
 
  return 0;
}
</source>
 
==CMakeLists.txt==
<source lang="cmake">
cmake_minimum_required(VERSION 2.6)
 
PROJECT(GradientMagnitudeImageFilter)
 
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})
 
ADD_EXECUTABLE(GradientMagnitudeImageFilter GradientMagnitudeImageFilter.cxx)
TARGET_LINK_LIBRARIES(Gradient ITKNumerics ITKIO ITKAlgorithms)
 
</source>

Latest revision as of 16:09, 31 May 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.

[ITK Sphinx Examples]