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

Harold boogiedoll at yahoo.com
Tue Jan 7 23:58:54 EST 2014


Hi David,

I couldn't find any method to input customized array in vtkImageHistogram. I'm trying to plot image projection profile. I guess I can only use vtkChartXY.
Thanks for the reply.

Regards,
Harold



On Wednesday, January 8, 2014 1:24 PM, David Gobbi <david.gobbi at gmail.com> wrote:
 
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140107/0d0bf304/attachment.htm>


More information about the vtkusers mailing list