1 #ifndef vil_histogram_h_ 2 #define vil_histogram_h_ 12 # include <vcl_msvc_warnings.h> 14 #include <vxl_config.h> 21 std::vector<double>& histo,
22 double min,
double max,
unsigned n_bins)
25 std::fill(histo.begin(),histo.end(),0.0);
26 double x0 = double(
min);
27 double s = double(n_bins-1)/(double(
max)-x0);
29 unsigned ni = image.
ni(),nj = image.
nj(),np = image.
nplanes();
32 for (
unsigned p=0;p<np;++p,plane += pstep)
35 for (
unsigned j=0;j<nj;++j,row += jstep)
38 for (
unsigned i=0;i<ni;++i,pixel+=istep)
40 int index = int(0.5+s*(
double(*pixel) - x0));
41 if (index>=0 && (
unsigned)index<n_bins) histo[index]+=1;
51 std::vector<double>& histo);
54 #define VIL_HISTOGRAM_INSTANTIATE(T) \ 55 template void vil_histogram(const vil_image_view<T>& image, \ 56 std::vector<double>& histo, \ 57 double min, double max, unsigned n_bins) 59 #endif // vil_histogram_h_ Concrete view of image data of type T held in memory.
std::ptrdiff_t jstep() const
Add this to your pixel pointer to get next j pixel.
unsigned ni() const
Width.
unsigned nj() const
Height.
void vil_histogram(const vil_image_view< T > &image, std::vector< double > &histo, double min, double max, unsigned n_bins)
Construct histogram from pixels in given image.
std::ptrdiff_t planestep() const
Add this to your pixel pointer to get pixel on next plane.
A base class reference-counting view of some image data.
vnl_decnum max(vnl_decnum const &x, vnl_decnum const &y)
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.
vnl_decnum min(vnl_decnum const &x, vnl_decnum const &y)
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.