[vtkusers] VTKWiki, VTK/Examples/Histogram
David Doria
daviddoria+vtk at gmail.com
Tue Jan 5 14:23:17 EST 2010
On Tue, Jan 5, 2010 at 1:09 PM, Dean Inglis <dean.inglis at camris.ca> wrote:
> Ive revised the example Histogram.cxx. If you pass
> it a 3 channel image or less, the image gets broken
> up into its constituent components using vtkImageExtractComponents
> and a histogram is generated for each component.
> While experimenting with a 3 channel jpeg ( VTKData/Data/beach.jpg)
> I tried to limit the yscale of the vtkXYPlotActor to the maximum frequency
> range,
> but the maximum was always a large count corresponding to the value 0.
> Hence the plot gets a large spike at 0 and the remaining frequencies appear
> relatively small. If you set IgnoreZero to true for vtkImageAccumulate, it
> will still increment the bin count for value 0. Is this an error?
>
> if( !ignoreZero || double(*subPtr) != 0. ) // this is fine if
> ignore zero is true and the value is zero
> {
> // Gather statistics
> sum[idxC] += *subPtr;
> sumSqr[idxC] += (*subPtr * *subPtr);
> if (*subPtr > max[idxC])
> {
> max[idxC] = *subPtr;
> }
> if (*subPtr < min[idxC])
> {
> min[idxC] = *subPtr;
> }
> (*voxelCount)++;
> }
> // compute the index
> outIdx = static_cast<int>((static_cast<double>(*subPtr++) -
> origin[idxC]) / spacing[idxC]);
> if (outIdx < outExtent[idxC*2] || outIdx > outExtent[idxC*2+1])
> {
> // Out of bin range
> outPtrC = NULL;
> break;
> }
> outPtrC += (outIdx - outExtent[idxC*2]) * outIncs[idxC];
> }
> if (outPtrC) // regardless of whether ignore zero is true, it seems
> that the bin for value 0 gets incremented anyway
> {
> ++(*outPtrC);
> }
>
> I was figuring that histogram->GetOutput()->GetScalarRange()[1] would return
> the max frequency (in the case of unsigned char data), and it does, its just
> in this
> particular case when the frequency is maximum for value 0, ignorezero doenst
> do what
> I hoped it would do. Altering the last if condition would fix this wouldnt
> it?:
>
> if (outPtrC && (!ignoreZero || double(*subPtr) != 0.))
> {
> ++(*outPtrC);
> }
>
> Dean
Dean -
I don't know the answer to your question - but I separated the example
to demonstrate the BarChar separately:
http://www.cmake.org/Wiki/VTK/Examples/Histogram
http://www.cmake.org/Wiki/VTK/Examples/HistogramBarChart
Let me know if you have an objection.
Thanks,
David
More information about the vtkusers
mailing list