ITK/Examples/SimpleOperations/ScalarToRGBColormapImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
No edit summary
(Deprecated content that is moved to sphinx)
 
Line 1: Line 1:
==ScalarToRGBColormapImageFilter.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 "itkImageRegionConstIterator.h"
#include "itkScalarToRGBColormapImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkImageFileWriter.h"
#include "itkRGBPixel.h"


typedef itk::RGBPixel<unsigned char>    RGBPixelType;
[https://itk.org/ITKExamples[ITK Sphinx Examples]]
typedef itk::Image<RGBPixelType, 2>  RGBImageType;
 
typedef itk::Image<float, 2>  FloatImageType;
typedef itk::Image<unsigned char, 2>  UnsignedCharImageType;
 
int main( int argc, char *argv[])
{
  FloatImageType::Pointer image = FloatImageType::New();
 
  itk::Index<2> start;
  start.Fill(0);
 
  itk::Size<2> size;
  size.Fill(20);
 
  itk::ImageRegion<2> region(start, size);
 
  image->SetRegions(region);
  image->Allocate();
 
  for(unsigned int i = 0; i < 20; i++)
    {
    for(unsigned int j = 0; j < 20; j++)
      {
      itk::Index<2> pixel;
      pixel[0] = i;
      pixel[1] = j;
      image->SetPixel(pixel, j);
      }
    }
 
  typedef itk::RescaleIntensityImageFilter< FloatImageType, UnsignedCharImageType > RescaleFilterType;
  RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
  rescaleFilter->SetInput(image);
  rescaleFilter->SetOutputMinimum(0);
  rescaleFilter->SetOutputMaximum(255);
  rescaleFilter->Update();
 
  {
  typedef  itk::ImageFileWriter< UnsignedCharImageType > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName("original.png");
  writer->SetInput(rescaleFilter->GetOutput());
  writer->Update();
  }
 
  typedef itk::ScalarToRGBColormapImageFilter<FloatImageType, RGBImageType> RGBFilterType;
  RGBFilterType::Pointer rgbfilter = RGBFilterType::New();
  rgbfilter->SetInput(image);
  rgbfilter->SetColormap( RGBFilterType::Hot );
 
  {
  typedef  itk::ImageFileWriter< RGBImageType > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName("hot.png");
  writer->SetInput(rgbfilter->GetOutput());
  writer->Update();
  }
 
  return EXIT_SUCCESS;
}
 
</source>
 
{{ITKCMakeLists|{{SUBPAGENAME}}}}

Latest revision as of 19:05, 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]