[vtkusers] VTKWiki, VTK/Examples/Histogram

Dean Inglis dean.inglis at camris.ca
Tue Jan 5 13:09:10 EST 2010


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 




More information about the vtkusers mailing list