25 #include "UnVignette.hh"
28 #include <MathAlgo/Lapack.hh>
29 #include <Base/Common/BIASpragma.hh>
30 #include <MathAlgo/SVD.hh>
31 #include <Base/Debug/TimeMeasure.hh>
39 PrinciplePointX_ = 0.0;
40 PrinciplePointY_ = 0.0;
41 bIsInitialized_ =
false;
43 bLeastSquaresPrepared_ =
false;
44 dInterPolationMethod_ = LEAST_SQUARES;
50 dInterPolationMethod_ = method;
52 bIsInitialized_ =
false;
53 bLeastSquaresPrepared_ =
false;
60 dWidthHalfMPPX_ = dWidth_/2 - PrinciplePointX_;
61 dHeightHalfMPPY_ = dHeight_/2 - PrinciplePointY_;
65 if(ControlPoints_.size() > 2 && PercentageValues_.size() > 2)
66 Init(cParam,method,bUseLuT_);
77 if (!bIsInitialized_){
78 BIASWARN(
"Unvignette is not initialised, doing nothing");
84 BIASERR(
"Image size does not fit init size, returning" );
88 unsigned int newPixelValue =0;
93 float* pLuId = LuImage_.GetImageData();
95 for(
unsigned int i=0;i<dWidth_*dHeight_;i++)
98 for(
unsigned int j=0;j<dChannelCount_;j++)
100 newPixelValue = (
unsigned int)( (*pId) * dum );
101 if(newPixelValue <= 255)
102 *pId++ = newPixelValue;
114 std::vector<double> PercentageValues,
115 unsigned int dImageWidth ,
unsigned int dImageHeight,
116 int dPPX,
int dPPY, INTERPOLATION_METHOD method,
bool bUseLuT)
119 dInterPolationMethod_ = method;
120 dWidth_ = dImageWidth;
121 dHeight_ = dImageHeight;
122 PrinciplePointX_ = dPPX - dWidth_/2;
123 PrinciplePointY_ = dPPY - dHeight_/2;
124 ControlPoints_ = ControlPoints;
125 PercentageValues_ = PercentageValues;
132 dInterPolationMethod_ = method;
142 int UnVignette::Init_(){
144 dWidthHalfMPPX_ = dWidth_/2 - PrinciplePointX_;
145 dHeightHalfMPPY_ = dHeight_/2 - PrinciplePointY_;
146 if(ControlPoints_.size() > 2 && PercentageValues_.size() > 2)
148 switch(dInterPolationMethod_){
149 case SPLINE_WITHOUT_LUT:
150 case SPLINE_WITH_LUT:
151 InterpolatorIllu_.SetKnotPoints(ControlPoints_);
152 InterpolatorIllu_.SetControlPoints(PercentageValues_);
153 InterpolatorIllu_.InitSpline();
156 ret = InterpolatorIllu_.PrepareLuTSpline(ControlPoints_[0],
157 ControlPoints_[ControlPoints_.size()-1],2000);
161 ret = PrepareLeastSquaresMin_();
165 ret = PrepareLuImage_();
167 bIsInitialized_ =
true;
177 CalcRadius_(
double x,
double y)
180 radius=sqrt((dWidthHalfMPPX_-x)*(dWidthHalfMPPX_-x) + (dHeightHalfMPPY_-y)*(dHeightHalfMPPY_-y));
191 dWidthHalfMPPX_ = dWidth_/2 - PrinciplePointX_;
192 dHeightHalfMPPY_ = dHeight_/2 - PrinciplePointY_;
194 LuImage_.Init(dWidth_,dHeight_,1);
195 float ** ida = LuImage_.GetImageDataArray();
197 for(
unsigned int k=0;k<LuImage_.GetWidth();k++)
199 for(
unsigned int l=0;l<LuImage_.GetHeight();l++)
201 radius = CalcRadius_(k,l);
202 if(radius<0.0) radius = 0.0;
203 switch(dInterPolationMethod_){
204 case SPLINE_WITH_LUT:
205 case SPLINE_WITHOUT_LUT :
207 InterpolatorIllu_.SplineFromLuT(dum, radius/(dWidth_/2));
209 InterpolatorIllu_.Spline(dum,radius/(dWidth_/2),3);
212 LeastSquares_(dum,radius/(dWidth_/2));
217 ida[l][k] = (float)dum;
225 PrepareLeastSquaresMin_()
228 int rows = PercentageValues_.size();
231 for(
int row=0;row<rows;row++)
235 A_[row][1] = ControlPoints_[row];
236 A_[row][2] = pow(ControlPoints_[row],2);
237 A_[row][3] = pow(ControlPoints_[row],3);
238 Y_[row] = PercentageValues_[row];
243 res=svd.
Solve(A_,Y_,X_);
248 bLeastSquaresPrepared_ =
true;
250 bLeastSquaresPrepared_ =
false;
256 LeastSquares_(
double &res,
double radius)
258 if(!bLeastSquaresPrepared_)
260 BIASERR(
"Least Squares is not correctly prepared, aborting.");
264 res = X_[3]*pow(radius,3) + X_[2]*pow(radius,2) +X_[1]*radius + X_[0];
computes and holds the singular value decomposition of a rectangular (not necessarily quadratic) Matr...
unsigned int GetHeight() const
get camera image height.
Vector< double > Solve(const Vector< double > &y) const
int Init(const std::vector< double > ControlPoints, std::vector< double > PercentageValues, unsigned int dImageWidth, unsigned int dImageHeight, int dPPX, int dPPY, INTERPOLATION_METHOD method=LEAST_SQUARES, bool bUseLuT=true)
Init the Unvignette algorithm give ControlPoints in image as offset from Principal Point in pixel giv...
double GetPrincipalY() const
get principal point, y in pixels relative to top left corner
unsigned int GetWidth() const
unsigned int GetWidth() const
get camera image width.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
unsigned int GetHeight() const
std::vector< double > GetIlluCorrY() const
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
std::vector< double > GetIlluCorrX() const
void Compute(BIAS::Image< unsigned char > &Image)
double GetPrincipalX() const
get principal point, x in pixels relative to top left corner