Difference between revisions of "VTK/Examples/Cxx/Images/ImageLuminance"

From KitwarePublic
< VTK‎ | Examples‎ | Cxx
Jump to navigationJump to search
(Created page with '==ImageLuminance.cxx== <source lang="cpp"> #include <vtkSmartPointer.h> #include <vtkImageData.h> #include <vtkJPEGWriter.h> #include <vtkImageCanvasSource2D.h> #include <vtkImag…')
 
(No difference)

Revision as of 19:40, 30 April 2010

ImageLuminance.cxx

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

int main(int argc, char *argv[])
{
  //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)