[vtkusers] std::vector to vtkImageAccumulate to Draw a Histogram

Harold boogiedoll at yahoo.com
Tue Jan 7 23:12:02 EST 2014


Hi,

I have a grayscale image. I want to draw a histogram where x-axis is the nth column (n = image_width -1), and y-axis is the sum of pixel value in each column. How do I pass the y-axis value (std::vector<int> ColSum; ) to the vtkImageAccumulate?

// Read a jpeg image
  vtkSmartPointer<vtkJPEGReader> reader =
    vtkSmartPointer<vtkJPEGReader>::New();
  reader->SetFileName( argv[1] );
  reader->Update();

// Convert image to image data
  vtkSmartPointer<vtkImageData> imageData =
vtkSmartPointer<vtkImageData>::New();
  imageData = reader->GetOutput();

// Compute the sum for each image column 
  std::vector<int> ColSum; 
  int image_width =  imageData->GetDimensions()[0];
  ColSum.resize(width);
 
  for(int i = 0; i < image_width; ++i)
  {
  ColSum[i] = 0;
  for(int j = 0; j < height; ++j)
  {
  ColSum[i] += imageData->GetScalarComponentAsDouble(i,j, 0, 0);
  }
  }

// Draw histogram
  vtkSmartPointer<vtkImageAccumulate> histogram =
    vtkSmartPointer<vtkImageAccumulate>::New();
  // ??? How to convert  "ColSum" to vtkImageAccumulate  here?

  ...


Regards,
Harold
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140107/b6f56771/attachment.htm>


More information about the vtkusers mailing list