14 std::vector<double> histo(256);
19 for (
unsigned i=0;i<256;++i) { sum+=histo[i]; histo[i]=sum; }
24 while (histo[lo]==0) lo++;
25 double x0 = histo[lo];
26 double s =255.1/(sum-x0);
28 std::vector<vxl_byte> lookup(256);
29 vxl_byte* lup = &lookup[0];
30 for (
unsigned i=0;i<256;++i) { lup[i]= vxl_byte(s*(histo[i]-x0)); }
32 unsigned ni = image.
ni(),nj = image.
nj(),np = image.
nplanes();
35 for (
unsigned p=0;p<np;++p,plane += pstep)
37 vxl_byte* row = plane;
38 for (
unsigned j=0;j<nj;++j,row += jstep)
40 vxl_byte* pixel = row;
41 for (
unsigned i=0;i<ni;++i,pixel+=istep) *pixel = lup[*pixel];
49 unsigned n_bins = 4000;
50 std::vector<double> histo(n_bins);
61 for (
unsigned i=0; i<n_bins; ++i) { sum+=histo[i]; histo[i]=sum; }
65 while (histo[lo]==0) lo++;
66 double x0 = histo[lo];
68 double s_b2o =255.1/(sum-x0);
69 std::vector<unsigned> lookup_b2o(n_bins);
70 unsigned* lup_b2o = &lookup_b2o[0];
71 for (
unsigned i=0;i<n_bins;++i) { lup_b2o[i]=unsigned(s_b2o*(histo[i]-x0)); }
73 double s_i2b = double(n_bins-1)/(double(max_v-min_v));
74 std::vector<unsigned> lookup_i2b(max_v-min_v+1);
75 unsigned* lup_i2b = &lookup_i2b[0];
76 for (
unsigned i=0;i<=(max_v-min_v);++i) { lup_i2b[i]=unsigned(s_i2b*i); }
79 unsigned ni = image.
ni(), nj = image.
nj(), np = image.
nplanes();
82 for (
unsigned p=0; p<np; ++p, plane+=pstep)
85 for (
unsigned j=0;j<nj;++j,row += jstep)
88 for (
unsigned i=0; i<ni; ++i,pixel+=istep)
89 *pixel = lup_b2o[lup_i2b[(
unsigned)(*pixel-min_v)]];
Apply histogram equalisation to images.
void vil_histogram_equalise(vil_image_view< vxl_byte > &image)
Apply histogram equalisation to given byte image.
Various mathematical manipulations of 2D images.
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.
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.
void vil_math_value_range(const vil_image_view< T > &view, T &min_value, T &max_value)
Compute minimum and maximum values over view.