File: PrintWeights.cpp

package info (click to toggle)
luminance-hdr 2.6.1.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 34,788 kB
  • sloc: cpp: 43,954; ansic: 4,122; xml: 116; makefile: 20; sh: 7
file content (130 lines) | stat: -rw-r--r-- 3,374 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <vector>
#include <iostream>
#include <fstream>
#include <cmath>

#include <HdrCreation/weights.h>

using namespace std;
using namespace libhdr::fusion;

static const size_t SAMPLES = WeightFunction::NUM_BINS;

// OLD STUFF
#define MIN_WEIGHT 1e-3

void exposure_weights_icip06( float* w, int M, int Mmin, int Mmax )
{
    for( int m=0 ; m<M ; m++ )
        if( m<Mmin || m>Mmax )
            w[m] = 0.0f;
        else
            w[m]=1.0f-pow( ( (2.0f*float(m-Mmin)/float(Mmax-Mmin)) - 1.0f), 12.0f);
}

void weightsGauss( float* w, int M, int Mmin, int Mmax, float sigma  = 8.0f)
{
    float mid = Mmin + (Mmax-Mmin)/2.0f - 0.5f;
    float mid2 = (mid-Mmin) * (mid-Mmin);
    for( int m=0 ; m<M ; m++ ) {
        if ( m<Mmin || m>Mmax ) {
            w[m] = 0.0f;
        } else {
            // gkrawczyk: that's not really a gaussian, but equation is
            // taken from Robertson02 paper.
            float weight = exp( -sigma * (m-mid) * (m-mid) / mid2 );

            if( weight < MIN_WEIGHT )           // ignore very low weights
                w[m] = 0.0f;
            else
                w[m] = weight;
        }
    }
}

void weights_triangle( float* w, int M /*, int Mmin, int Mmax*/ )
{
    for(int i=0;i<int(float(M)/2.0f);i++) {
        w[i]=i/ (float(M)/2.0f);
        if (w[i]<0.06f)w[i]=0;
    }
    for(int i=int(float(M)/2.0f);i<M;i++) {
        w[i]=(M-1-i)/(float(M)/2.0f);
        if (w[i]<0.06f)w[i]=0;
    }
    //   for( int m=0 ; m<M ; m++ )
    //     if( m<Mmin || m>Mmax )
    //       w[m] = 0.0f;
    //     else
    //     {
    // 	if ( m<int(Mmin+ (Mmax-Mmin)/2.0f +1) )
    // 		w[m]=(m-Mmin)/float(Mmin+(Mmax-Mmin)/2.0f);
    // 	else
    // 		w[m]=( -m+Mmin+((Mmax-Mmin)) )/float(Mmin+(Mmax-Mmin)/2.0f);
    //     }

    // 	  if (w[i]<0.06f)w[i]=0;
}

void printTriangular()
{
    WeightFunction weights(WEIGHT_TRIANGULAR);
    vector<float> data(SAMPLES);

    ofstream outputFile("data_triangular.dat");
    weights_triangle(data.data(), SAMPLES);
    for (size_t idx = 0; idx < SAMPLES; ++idx)
    {
        float w = weights.getWeight(((float)idx)/SAMPLES);

        outputFile << idx << " " << data[idx] << " "
                   << w << " " << abs(data[idx] - w)
                   << "\n";
    }
    outputFile.close();
}

void printGaussian()
{
    WeightFunction weights(WEIGHT_GAUSSIAN);
    vector<float> data(SAMPLES);

    ofstream outputFile("data_gauss.dat");
    weightsGauss(data.data(), SAMPLES, 0, SAMPLES);
    for (size_t idx = 0; idx < SAMPLES; ++idx)
    {
        float w = weights.getWeight(((float)idx)/SAMPLES);

        outputFile << idx << " " << data[idx] << " "
                   << w << " " << abs(data[idx] - w)
                   << "\n";
    }
    outputFile.close();
}

void printPlateau()
{
    WeightFunction weights(WEIGHT_PLATEAU);
    vector<float> data(SAMPLES);

    ofstream outputFile("data_plateau.dat");
    exposure_weights_icip06(data.data(), SAMPLES, 0, SAMPLES);
    for (size_t idx = 0; idx < SAMPLES; ++idx)
    {
        float w = weights.getWeight(((float)idx)/SAMPLES);

        outputFile << idx << " " << data[idx] << " "
                   << w << " " << abs(data[idx] - w)
                   << "\n";
    }
    outputFile.close();
}

int main() // int argc, char** argv)
{
    printTriangular();
    printGaussian();
    printPlateau();

    return 0;
}