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

David Gobbi david.gobbi at gmail.com
Tue Jan 7 23:24:19 EST 2014


Hi Harold,

The vtkImageAccumulate filter doesn't draw a histogram, it computes
a histogram.  The input of vtkImageAccumulate is an image, not an
array.

It might be easier to use vtkImageHistogram.  It takes an image as
input, and produces a histogram image as output.

  David


On Tue, Jan 7, 2014 at 9:12 PM, Harold <boogiedoll at yahoo.com> wrote:
> 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


More information about the vtkusers mailing list