VTK/Examples/Cxx/Images/ImageLuminance

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Revision as of 16:46, 1 September 2010 by Daviddoria (talk | contribs)
Jump to navigationJump to search

ImageLuminance.cxx

#include <vtkSmartPointer.h>
#include <vtkImageData.h>
#include <vtkJPEGWriter.h>
#include <vtkImageCanvasSource2D.h>
#include <vtkImageLuminance.h>

int main(int, char *[])
{
  // Create an image of a rectangle
  vtkSmartPointer<vtkImageCanvasSource2D> source = 
    vtkSmartPointer<vtkImageCanvasSource2D>::New();
  source->SetScalarTypeToUnsignedChar();
  source->SetNumberOfScalarComponents(3);
  source->SetExtent(0, 200, 0, 200, 0, 0);
  
  // Clear the image
  source->SetDrawColor(0,0,0);
  source->FillBox(0,200,0,200);
  
  // Draw a red box
  source->SetDrawColor(255,0,0);
  source->FillBox(100,120,100,120);
  source->Update();
  
  // Write the original image
  {
  vtkSmartPointer<vtkJPEGWriter> writer = 
    vtkSmartPointer<vtkJPEGWriter>::New();
  writer->SetInputConnection(source->GetOutputPort());
  writer->SetFileName("orig.jpg");
  writer->Write();
  }
  
  vtkSmartPointer<vtkImageLuminance> luminanceFilter = 
    vtkSmartPointer<vtkImageLuminance>::New();
  luminanceFilter->SetInputConnection(source->GetOutputPort());
  luminanceFilter->Update();
  
  {
  vtkSmartPointer<vtkJPEGWriter> writer = 
    vtkSmartPointer<vtkJPEGWriter>::New();
  writer->SetInputConnection(luminanceFilter->GetOutputPort());
  writer->SetFileName("luminance.jpg");
  writer->Write();
  }
  
  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
PROJECT(ImageLuminance)

FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})

ADD_EXECUTABLE(ImageLuminance ImageLuminance.cxx)
TARGET_LINK_LIBRARIES(ImageLuminance vtkHybrid)