Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleHdr.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 /**
27  * @example ExampleHdr.cpp
28  @deprecated Schedule for removal!!
29  @relates SVD
30  @brief Example for Shit
31  @ingroup g_examples
32  @author MIP
33 */
34 
35 #include <Base/Image/Image.hh>
36 #include <Base/Math/Matrix.hh>
37 #include <Base/Math/Vector.hh>
38 #include <MathAlgo/SVD.hh>
39 
40 using namespace std;
41 using namespace BIAS;
42 
43 
44 //////////////////////////////////
45 //////////////////////////////////
46 // //
47 // THIS IS UNDER CONSTRUCTION //
48 // //
49 //////////////////////////////////
50 //////////////////////////////////
51 
52 
53 
54 
55 int main(int argc, char *argv[]) {
56 
57  return 0;
58 }
59 
60 //
61 // gsolve.m Solve for imaging system response function
62 //
63 // Given a set of pixel values observed for several pixels in several
64 // images with different exposure times, this function returns the
65 // imaging systems response function g as well as the log film irradiance
66 // values for the observed pixels.
67 //
68 // Assumes:
69 //
70 // Zmin = 0
71 // Zmax = 255
72 //
73 // Arguments:
74 //
75 // Z(i,j) is the pixel values of pixel location number i in image j
76 // B(j) is the log delta t, or log shutter speed, for image j
77 // l is lamdba, the constant that determines the amount of smoothness
78 // w(z) is the weighting function value for pixel value z
79 //
80 // Returns:
81 //
82 // g(z) is the log exposure corresponding to pixel value z
83 // lE(i) is the log film irradiance at pixel location i
84 //
85 
86 
87 void gsolve(BIAS::Matrix<unsigned char> Z, BIAS::Vector<double> B, double l,
89  const int n = sizeof(unsigned char);
90 
91  // prepare matrix for linear equation system
92  BIAS::Matrix<double> A(Z.num_rows() * Z.num_cols() + n + 1,
93  n + Z.num_rows(),
94  0.0);
95 
96  // prepare vector for linear equation system
97  BIAS::Vector<double> b(A.num_rows(), 1.0);
98 
99  // include the data-fitting equations
100  int k = 0;
101  double wij; // temp value
102  for (int i = 0; i < Z.num_rows(); i++) {
103  for (int j = 0; j < Z.num_cols(); j++) {
104  wij = w[Z[i][j] + 1]; // +1 ???
105  A[k][Z[i][j] + 1] = wij; // +1 ???
106  A[k][n + i] = -wij;
107  b[k] = wij * B[j];
108  k++;
109  }
110  }
111 
112  // Fix the curve by setting its middle value to 0
113  A[k][128] = 1;
114  k++;
115 
116  //Include the smoothness equations
117  for (int i = 0; i < n - 2; i++) {
118  A[k][i] = l * w[i+1]; // +1 ???
119  A[k][i+1] = -2 * l * w[i+1]; // +1 ???
120  A[k][i+2] = l * w[i+1]; // +1 ???
121  k++;
122  }
123 
124  // Solve the system using SVD
125  SVD svd;
127  svd.Solve(A, b, x);
128 
129  // get cam response function and irradiance from solution vector
131  BIAS::Vector<double> lE(x.size() - n);
132 
133  for (int i = 0; i < n; i++) {
134  g[i] = x[i];
135  }
136 
137  for (int i = n; i < x.size(); i++) {
138  lE[i - n] = x[i];
139  }
140 
141  // TODO: return g and lE
142 }
143 
144 
145 
146 /*
147 function [g,lE]=gsolve(Z,B,l,w)
148 //n = 256;
149 //A = zeros(size(Z,1)*size(Z,2)+n+1,n+size(Z,1));
150 //b = zeros(size(A,1),1);
151 %% Include the data fitting equations
152 k = 1;
153 for i=1:size(Z,1)
154  for j=1:size(Z,2)
155  wij = w(Z(i,j)+1);
156  A(k,Z(i,j)+1) = wij;
157  A(k,n+i) = wij;
158  b(k,1) = wij * B(i,j); %%%%%%%%%%%% <-------- may be wrong! B is a vector
159  k=k+1;
160  end
161 end
162 %% Fix the curve by setting its middle value to 0
163 A(k,129) = 1;
164 k=k+1;
165 %% Include the smoothness equations
166 for i=1:n2
167  A(k,i)=l*w(i+1);
168  A(k,i+1)=2*l*w(i+1);
169  A(k,i+2)=l*w(i+1);
170  k=k+1;
171 end
172 %% Solve the system using SVD
173 x = A\b;
174 g = x(1:n);
175 lE = x(n+1:size(x,1));
176 */
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
Definition: SVD.hh:92
Subscript num_cols() const
Definition: cmat.h:320
Vector< double > Solve(const Vector< double > &y) const
Definition: SVD.cpp:135
matrix class with arbitrary size, indexing is row major.
Subscript num_rows() const
Definition: cmat.h:319
Subscript size() const
Definition: vec.h:262