18 #ifndef PIC_HISTOGRAM_HPP 19 #define PIC_HISTOGRAM_HPP 98 return powf(10.0f, x) -
epsilon;
122 if((indx >=
nBin) || (indx < 0)) {
123 printf(
"Error in Calculate %d.\n",indx);
214 BBox *box = NULL,
int channel = 0)
216 if((imgIn == NULL) || (channel < 0) ) {
230 bool c1 = (
nBin != this->
nBin) && (bin != NULL);
231 bool c2 = (
bin == NULL);
252 for(
int i = channel; i < size; i += channels) {
253 float val = imgIn->
data[i];
258 for(
int k = box->z0; k < box->z1; k++) {
259 for(
int j = box->y0; j < box->y1; j++) {
260 for(
int i = box->x0; i < box->x1; i++) {
261 float *tmp_data = (*imgIn)(i, j, k);
277 for(
int i = channel; i < size; i += channels) {
281 for(
int k = box->z0; k < box->z1; k++) {
282 for(
int j = box->y0; j < box->y1; j++) {
283 for(
int i = box->x0; i < box->x1; i++) {
284 float *tmp_data = (*imgIn)(i, j, k);
285 update(tmp_data[channel]);
300 bool c1 = (
nBin != this->
nBin) && (bin != NULL);
301 bool c2 = (
bin == NULL);
354 float indf = float(ind);
370 std::vector<bool> trimmed_vec;
372 while((trimmings <= tolerance) && bFlag) {
379 bool bTrimmed =
false;
382 for(
int i = 0; i <
nBin; i++) {
390 trimmed_vec.push_back(bTrimmed);
394 int tvSize = int(trimmed_vec.size());
396 bool b0 = !trimmed_vec[tvSize - 1];
397 bool b1 = !trimmed_vec[tvSize - 2];
412 for(
int i = 0; i <
nBin; i++) {
414 redistrib +=
bin[i] - value + 1;
419 int nCount = redistrib /
nBin;
421 for(
int i = 0; i < nCount; i++) {
422 for(
int j = 0; j <
nBin; j++) {
427 int remainder = redistrib %
nBin;
429 for(
int i =0; i < remainder; i++) {
502 for(
int i = 0; i <
nBin; i++) {
525 for(
int i = 0; i <
nBin; i++) {
529 float sigma_b_max = 0.0f;
530 for(
int i = 1; i <
nBin; i++) {
539 if(w0 > 0.0f && w1 > 0.0f) {
540 float delta = (mu0 / w0) - (mu1 / w1);
541 float sigma_b = w0 * w1 * delta * delta;
543 if(sigma_b > sigma_b_max) {
544 sigma_b_max = sigma_b;
558 void write(std::string name,
bool bNor)
566 for(
int i = 0; i <
nBin; i++) {
587 std::vector< float > ret;
591 printf(
"ERROR in ExposureCovering: this histogram has to be in log2!\n");
599 int removingBins = int(
float(nBits) /dMM + overlap);
614 for(
int i = 0; i < (
nBin - removingBins); i++) {
617 for(
int j = i; j < (i + removingBins); j++) {
621 if(tmpCount > count) {
635 for(
int j = index; j < (index + removingBins); j++) {
639 float fstop = (float(index + removingBins) * dMM) +
fMin;
655 printf(
"%f\n", fstop);
656 ret.push_back(fstop);
675 float nBits_f = float(nBits);
681 int range_size_hist = int(
float(nBits) /dMM + overlap);
682 range_size_hist = (range_size_hist < 1) ? 2 : range_size_hist;
685 printf(
"Histogram [%f %f] %d\n",
fMin,
fMax, range_size_hist);
691 for(
int i = 0; i < (
nBin - range_size_hist); i++) {
694 for(
int j = i; j < (i + range_size_hist); j++) {
698 if(tmpCount > count) {
704 float fstop_index = (float(index + range_size_hist) * dMM) +
fMin;
The BBox class manages the creation of bounding boxes for images.
Definition: bbox.hpp:29
unsigned int uint
Definition: base.hpp:23
float * bin_nor
Definition: histogram.hpp:41
float * cumulativef(bool bNormalized)
cumulativef computes the cumulative Histogram.
Definition: histogram.hpp:440
void calculate(Image *imgIn, VALUE_SPACE type=VS_LIN, int nBin=256, BBox *box=NULL, int channel=0)
calculate computes the histogram of an input image. In the case of LDR images, they are ssumed to be ...
Definition: histogram.hpp:213
float * data
data is the main buffer where pixel values are stored.
Definition: image.hpp:91
void write(std::string name, bool bNor)
write saves the Histogram as an Image into a file.
Definition: histogram.hpp:558
int channels
Definition: image.hpp:80
The Histogram class is a class for creating, managing, loading, and saving histogram for an Image...
Definition: histogram.hpp:37
void update(float fMin, float fMax)
update
Definition: histogram.hpp:325
Definition: histogram.hpp:31
float * bin_c
Definition: histogram.hpp:40
T * delete_vec_s(T *data)
delete_vec_s
Definition: std_util.hpp:138
float unprojectDomain(float x)
unprojectDomain removes the histogram domain to x.
Definition: histogram.hpp:84
uint * bin
Definition: histogram.hpp:131
void clip(uint value)
clip clips the histogram to value.
Definition: histogram.hpp:409
float * getCumulativef()
getCumulativef this function returns the cumulative Histogram. Note that cumulativef needs to be comp...
Definition: histogram.hpp:459
VALUE_SPACE
Definition: histogram.hpp:31
float * getNormalized(bool bNor=true)
getNormalized normalizes the Histogram.
Definition: histogram.hpp:487
float getfMin()
getfMin
Definition: histogram.hpp:468
Histogram()
Histogram is the basic constructor setting variables to defaults.
Definition: histogram.hpp:136
VALUE_SPACE type
Definition: histogram.hpp:43
void ceiling(float k)
ceiling limits the maximum value of the histogram using Ward algorithm.
Definition: histogram.hpp:364
float projectDomain(float x)
projectDomain applies the histogram domain to x.
Definition: histogram.hpp:53
Definition: histogram.hpp:31
int project(float x)
project converts an input value in the histogram domain.
Definition: histogram.hpp:337
Definition: histogram.hpp:31
Definition: histogram.hpp:31
float fMax
Definition: histogram.hpp:44
float deltaMaxMin
Definition: histogram.hpp:45
float unproject(int ind)
unproject converts a histogram value back to its original domain.
Definition: histogram.hpp:352
float fMin
Definition: histogram.hpp:44
float getfMax()
getfMax
Definition: histogram.hpp:478
std::vector< float > exposureCovering(int nBits=8, float overlap=1.0f)
exposureCovering computes the exposure values for fully covering the dynamic range of the image...
Definition: histogram.hpp:585
static T * cumsum(T *vec, int size, T *ret)
cumsum
Definition: array.hpp:438
#define MIN(a, b)
Definition: math.hpp:69
Definition: dynamic_range.hpp:29
The Image class stores an image as buffer of float.
Definition: image.hpp:60
float getBestExposure(int nBits, float overlap=0.5f)
getBestExposure computes the best interval center.
Definition: histogram.hpp:669
static void div(T *data, int size, T value)
div
Definition: array.hpp:353
const float C_INV_LOG_NAT_2
Definition: math.hpp:36
float getOtsu()
getOtsu
Definition: histogram.hpp:516
Histogram(Image *imgIn, VALUE_SPACE type, int nBin, int channel=0)
Histogram is an extension of the basic constructor, where calculate is called in order to populate th...
Definition: histogram.hpp:159
int nBin
Definition: histogram.hpp:42
void release()
release
Definition: histogram.hpp:191
The Array class.
Definition: array.hpp:30
Definition: bilateral_separation.hpp:25
bool isValid()
isValid checks if the current image is valid, which means if they have an allocated buffer or not...
#define CLAMP(x, a)
Definition: math.hpp:77
static T * assign(T *data, int size, T *ret)
assign
Definition: array.hpp:464
#define MAX(a, b)
Definition: math.hpp:73
float epsilon
Definition: histogram.hpp:46
float nBinf
Definition: histogram.hpp:45
int width
Definition: image.hpp:80
void uniform(float fMin, float fMax, uint value, VALUE_SPACE type, int nBin)
uniform
Definition: histogram.hpp:298
int height
Definition: image.hpp:80
void update(float x)
update
Definition: histogram.hpp:115
bool Write(std::string nameFile, LDR_type typeWrite, int writerCounter)
Write saves an Image into a file on the disk.
~Histogram()
~Histogram is the basic destructor which frees memory.
Definition: histogram.hpp:178
uint * bin_work
Definition: histogram.hpp:131
Definition: histogram.hpp:31