vil_histogram.cxx
Go to the documentation of this file.
1 //:
2 // \file
3 // \brief Construct histogram from pixels in given image.
4 // \author Tim Cootes
5 
6 #include "vil_histogram.h"
7 
8 //: Construct histogram from pixels in given image of bytes
9 // Resulting histogram has 256 bins
11  std::vector<double>& histo)
12 {
13  histo.resize(256);
14  std::fill(histo.begin(),histo.end(),0.0);
15 
16  unsigned ni = image.ni(),nj = image.nj(),np = image.nplanes();
17  std::ptrdiff_t istep=image.istep(),jstep=image.jstep(),pstep = image.planestep();
18  const vxl_byte* plane = image.top_left_ptr();
19  for (unsigned p=0;p<np;++p,plane += pstep)
20  {
21  const vxl_byte* row = plane;
22  for (unsigned j=0;j<nj;++j,row += jstep)
23  {
24  const vxl_byte* pixel = row;
25  for (unsigned i=0;i<ni;++i,pixel+=istep) histo[*pixel]+=1;
26  }
27  }
28 }
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
std::ptrdiff_t jstep() const
Add this to your pixel pointer to get next j pixel.
unsigned ni() const
Width.
unsigned nj() const
Height.
std::ptrdiff_t planestep() const
Add this to your pixel pointer to get pixel on next plane.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
unsigned nplanes() const
Number of planes.
void vil_histogram_byte(const vil_image_view< vxl_byte > &image, std::vector< double > &histo)
Construct histogram from pixels in given image of bytes.
Construct histogram from pixels in given image.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.