core/vil/algo/vil_histogram.cxx
Go to the documentation of this file.
00001 //:
00002 // \file
00003 // \brief Construct histogram from pixels in given image.
00004 // \author Tim Cootes
00005 
00006 #include "vil_histogram.h"
00007 
00008 //: Construct histogram from pixels in given image of bytes
00009 //  Resulting histogram has 256 bins
00010 void vil_histogram_byte(const vil_image_view<vxl_byte>& image,
00011                         vcl_vector<double>& histo)
00012 {
00013   histo.resize(256);
00014   vcl_fill(histo.begin(),histo.end(),0.0);
00015 
00016   unsigned ni = image.ni(),nj = image.nj(),np = image.nplanes();
00017   vcl_ptrdiff_t istep=image.istep(),jstep=image.jstep(),pstep = image.planestep();
00018   const vxl_byte* plane = image.top_left_ptr();
00019   for (unsigned p=0;p<np;++p,plane += pstep)
00020   {
00021     const vxl_byte* row = plane;
00022     for (unsigned j=0;j<nj;++j,row += jstep)
00023     {
00024       const vxl_byte* pixel = row;
00025       for (unsigned i=0;i<ni;++i,pixel+=istep) histo[*pixel]+=1;
00026     }
00027   }
00028 }