Difference between revisions of "ITK/Examples/ImageProcessing/MultiplyByConstantImageFilter"

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Deprecated content that is moved to sphinxe)
 
(7 intermediate revisions by 3 users not shown)
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"
#include "itkMultiplyImageFilter.h"
#include "itkImageRegionConstIterator.h"


typedef itk::Image<unsigned char, 2>  ImageType;
[https://itk.org/ITKExamples[ITK Sphinx Examples]]
 
void OutputImage(ImageType::Pointer image);
 
int main( int argc, char *argv[])
{
 
  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);
 
  typedef itk::MultiplyImageFilter<ImageType, unsigned char, ImageType> MultiplyByConstantImageFilterType;
  MultiplyByConstantImageFilterType::Pointer multiplyByConstantImageFilter = MultiplyByConstantImageFilterType::New();
  multiplyByConstantImageFilter->SetInput(image);
  multiplyByConstantImageFilter->SetConstant(3);
  multiplyByConstantImageFilter->Update();
 
  OutputImage(multiplyByConstantImageFilter->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|MultiplyByConstantImageFilter|vtkHybrid}}

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]