contrib/mul/vil3d/algo/vil3d_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 "vil3d_histogram.h"
00007 
00008 //: Construct histogram from pixels in given image of bytes
00009 //  Resulting histogram has 256 bins
00010 void vil3d_histogram_byte(const vil3d_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   const vxl_byte* plane = image.origin_ptr();
00017   unsigned ni = image.ni(),nj = image.nj(),nk = image.nk(),np = image.nplanes();
00018   vcl_ptrdiff_t istep=image.istep(),jstep=image.jstep(),kstep=image.kstep(),pstep = image.planestep();
00019   for (unsigned p=0;p<np;++p,plane += pstep)
00020   {
00021     const vxl_byte* slice = plane;
00022     for (unsigned k=0;k<nk;++k,slice += kstep)
00023     {
00024       const vxl_byte* row = slice;
00025       for (unsigned j=0;j<nj;++j,row += jstep)
00026       {
00027         const vxl_byte* pixel = row;
00028         for (unsigned i=0;i<ni;++i,pixel+=istep) histo[*pixel]+=1;
00029       }
00030     }
00031   }
00032 }