ITK/Examples/ImageProcessing/MultiplyByConstantImageFilter

From KitwarePublic
< ITK‎ | Examples
Revision as of 15:12, 25 January 2011 by Daviddoria (talk | contribs) (Created page with "==MultiplyByConstantImageFilter.cxx== <source lang="cpp"> #include "itkImage.h" #include "itkMultiplyByConstantImageFilter.h" #include "itkImageRegionConstIterator.h" typedef it...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

MultiplyByConstantImageFilter.cxx

#include "itkImage.h"
#include "itkMultiplyByConstantImageFilter.h"
#include "itkImageRegionConstIterator.h"

typedef itk::Image<unsigned char, 2>  ImageType;

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::MultiplyByConstantImageFilter<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;
    }

}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

PROJECT(MultiplyByConstantImageFilter)

FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})

ADD_EXECUTABLE(MultiplyByConstantImageFilter MultiplyByConstantImageFilter.cxx)
TARGET_LINK_LIBRARIES(MultiplyByConstantImageFilter ITKIO)