ITK/Examples/Inspection/CheckerBoardImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
No edit summary
(Deprecated content that is moved to sphinx)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
Checkerboards are a convenient way to compare two images. This example displays a black and white checkerboard. Optionally you can provide one or two rgb triples (scaled 0-255). Then this example is convenient for comparing paint colors. For a site that converts vendor paint names to rub, see: [http://www.color-swatches.com].
{{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.
}}


<div class="floatcenter">[[File:ITK_Examples_Baseline_Inspection_TestCheckerBoardImageFilter.png]]</div>
[https://itk.org/ITKExamples[ITK Sphinx Examples]]
==CheckerBoardImageFilter.cxx==
<source lang="cpp">
#include "itkImage.h"
#include "itkRGBPixel.h"
#include "itkCheckerBoardImageFilter.h"
#include "itkImageRegionIterator.h"
 
#include "QuickView.h"
 
typedef itk::RGBPixel<unsigned char> PixelType;
typedef itk::Image<PixelType, 2> ImageType;
 
static void CreateImage(ImageType::Pointer image, PixelType);
 
int main(int argc, char *argv[])
{
  ImageType::Pointer image1 = ImageType::New();
  PixelType pixel1;
  pixel1.Fill(0);
  if (argc > 3)
    {
    pixel1.SetRed(atoi(argv[1]));
    pixel1.SetGreen(atoi(argv[2]));
    pixel1.SetBlue(atoi(argv[3]));
    }
  CreateImage(image1, pixel1);
  ImageType::Pointer image2 = ImageType::New();
 
  PixelType pixel2;
  pixel2.Fill(255);
  if (argc > 6)
    {
    pixel2.SetRed(atoi(argv[4]));
    pixel2.SetGreen(atoi(argv[5]));
    pixel2.SetBlue(atoi(argv[6]));
    }
  CreateImage(image2, pixel2);
 
  typedef itk::CheckerBoardImageFilter< ImageType > CheckerBoardFilterType;
  CheckerBoardFilterType::Pointer checkerBoardFilter = CheckerBoardFilterType::New();
  checkerBoardFilter->SetInput1(image1);
  checkerBoardFilter->SetInput2(image2);
  checkerBoardFilter->Update();
 
  QuickView viewer;
  viewer.AddImage<ImageType>(image1);
  viewer.AddImage<ImageType>(image2);
  viewer.AddImage<ImageType>(checkerBoardFilter->GetOutput());
  viewer.Visualize();
  return EXIT_SUCCESS;
}
 
void CreateImage(ImageType::Pointer image, PixelType color)
{
  // Create an image with all pixels set to 'color'
 
  ImageType::IndexType start;
  start.Fill(0);
 
  ImageType::SizeType size;
  size.Fill(100);
 
  ImageType::RegionType region;
  region.SetSize(size);
  region.SetIndex(start);
 
  image->SetRegions(region);
  image->Allocate();
 
  itk::ImageRegionIterator<ImageType> imageIterator(image,region);
 
  while(!imageIterator.IsAtEnd())
    {
    imageIterator.Set(color);
 
    ++imageIterator;
    }
}
</source>
 
{{ITKVTKCMakeLists|{{SUBPAGENAME}}}}

Latest revision as of 20:15, 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]