ITK/Examples/ImageProcessing/MultiplyByConstantImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(argc/argv not used)
(Deprecated content that is moved to sphinxe)
 
Line 1: Line 1:
==MultiplyByConstantImageFilter.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"
#if ITK_VERSION_MAJOR >= 4
#include "itkMultiplyImageFilter.h"
#else
#include "itkMultiplyByConstantImageFilter.h"
#endif
#include "itkImageRegionConstIterator.h"


typedef itk::Image<unsigned char, 2>  ImageType;
[https://itk.org/ITKExamples[ITK Sphinx Examples]]
 
static void OutputImage(ImageType::Pointer image);
 
int main( int, char *[])
{
 
  ImageType::Pointer image = ImageType::New();
 
  itk::Index<2> start;
  start.Fill(0);
 
  itk::Size<2> size;
  size.Fill(3);
 
  itk::ImageRegion<2> region(start, size);
 
  image->SetRegions(region);
  image->Allocate();
  image->FillBuffer(2);
 
  OutputImage(image);
 
#if ITK_VERSION_MAJOR >= 4
  typedef itk::MultiplyImageFilter<ImageType, ImageType, ImageType> MultiplyImageFilterType;
#else
  typedef itk::MultiplyByConstantImageFilter<ImageType, unsigned char, ImageType> MultiplyImageFilterType;
#endif
  MultiplyImageFilterType::Pointer multiplyImageFilter = MultiplyImageFilterType::New();
  multiplyImageFilter->SetInput(image);
#if ITK_VERSION_MAJOR >= 4
  multiplyImageFilter->SetConstant(3);
#else
  multiplyImageFilter->Update();
#endif
 
  OutputImage(multiplyImageFilter->GetOutput());
 
  return EXIT_SUCCESS;
}
 
void OutputImage(ImageType::Pointer image)
{
  itk::ImageRegionConstIterator<ImageType> imageIterator(image,image->GetLargestPossibleRegion());
 
  while(!imageIterator.IsAtEnd())
    {
    // Get the value of the current pixel
    unsigned char val = imageIterator.Get();
    std::cout << (int)val << std::endl;
 
    ++imageIterator;
    }
}
</source>
 
{{ITKCMakeLists|{{SUBPAGENAME}}}}

Latest revision as of 14:35, 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]