26 #include "IntegralHistogram.hh"
27 #include <Base/Image/ImageBase.hh>
28 #include <Base/Image/ImageConvert.hh>
29 #include <Base/Debug/TimeMeasure.hh>
31 #include <Base/Common/BIASpragma.hh>
91 histo -= mHists_[ly-1][ux-1];
92 histo -= mHists_[uy-1][lx-1];
93 histo += mHists_[uy-1][ux-1];
95 else if(uy==0 && ux >0)
97 histo -= mHists_[ly-1][ux-1];
99 else if(ux==0 && uy >0)
101 histo -= mHists_[uy-1][lx-1];
114 BIASERR(
"GenerateIntegralHist() needs an image with HSL Colormodel!");
118 if(nBinsize != nOldBinsize_)
120 nBinsize_ = nBinsize;
121 nOldBinsize_ = nBinsize;
123 nBinsizeSat_ = nBinsize;
124 nOldBinsizeSat_ = nBinsize;
129 const int nStep = 256/nBinsize_;
130 const int nStep2=nStep*nStep;
131 const int nNumIndex=nStep2+nStep;
132 unsigned char hue=0, sat=0, light=0;
136 tmp=tmp>>1; nShift_++;
141 if(mHists_.size() != nWidth*nHeight){
143 mHists_.newsize(nHeight, nWidth);
150 uData = lData = &(mHists_[0][0]);
151 RowEnd = uData + nWidth;
152 end = uData + nWidth*nHeight;
156 hue = (*pData++)>>nShift_;
158 light = (*pData++)>>nShift_;
161 (*lData)[hue*nStep+sat]++;
163 (*lData)[nStep2+light]++;
165 (*lData)[nNumIndex]=1;
168 while (lData < RowEnd){
169 CopyNoCheck(lData[-1], *lData);
170 hue = (*pData++)>>nShift_;
172 light = (*pData++)>>nShift_;
175 (*lData)[hue*nStep+sat]++;
177 (*lData)[nStep2+light]++;
179 (*lData)[nNumIndex]++;
189 hue = (*pData++)>>nShift_;
191 light = (*pData++)>>nShift_;
194 (*lData)[hue*nStep+sat]++;
196 (*lData)[nStep2+light]++;
198 (*lData)[nNumIndex]++;
201 while (lData < RowEnd){
205 hue = (*pData++)>>nShift_;
207 light = (*pData++)>>nShift_;
210 (*lData)[hue*nStep+sat]++;
212 (*lData)[nStep2+light]++;
214 (*lData)[nNumIndex]++;
233 int nBinsizeHue,
int nBinsizeSat)
240 BIASERR(
"GenerateIntegralHist() needs an image with HSL Colormodel!");
244 if(nBinsizeHue != nOldBinsize_)
246 nBinsize_ = nBinsizeHue;
247 nOldBinsize_ = nBinsizeHue;
249 if(nBinsizeSat != nOldBinsizeSat_)
251 nBinsizeSat_ = nBinsizeSat;
252 nOldBinsizeSat_ = nBinsizeSat;
258 const int nStep = 256/nBinsize_;
259 const int nStepSat = 256/nBinsizeSat_;
260 const int nStep2Sat = nStepSat*nStep;
261 const int nNumIndex=nStep2Sat+nStep;
262 unsigned char hue=0, sat=0, light=0;
266 tmp=tmp>>1; nShift_++;
272 tmp=tmp>>1; nShiftSat_++;
278 if(mHists_.size() != nWidth*nHeight){
280 mHists_.newsize(nHeight, nWidth);
287 uData = lData = &(mHists_[0][0]);
288 RowEnd = uData + nWidth;
289 end = uData + nWidth*nHeight;
293 hue = (*pData++)>>nShift_;
295 light = (*pData++)>>nShift_;
297 sat = sat>>nShiftSat_;
298 (*lData)[hue*nStepSat+sat]++;
300 (*lData)[nStep2Sat+light]++;
302 (*lData)[nNumIndex]=1;
305 while (lData < RowEnd){
306 CopyNoCheck(lData[-1], *lData);
307 hue = (*pData++)>>nShift_;
309 light = (*pData++)>>nShift_;
311 sat = sat>>nShiftSat_;
312 (*lData)[hue*nStepSat+sat]++;
314 (*lData)[nStep2Sat+light]++;
316 (*lData)[nNumIndex]++;
327 hue = (*pData++)>>nShift_;
329 light = (*pData++)>>nShift_;
331 sat = sat>>nShiftSat_;
332 (*lData)[hue*nStepSat+sat]++;
334 (*lData)[nStep2Sat+light]++;
336 (*lData)[nNumIndex]++;
339 while (lData < RowEnd){
343 hue = (*pData++)>>nShift_;
345 light = (*pData++)>>nShift_;
347 sat = sat>>nShiftSat_;
349 (*lData)[hue*nStepSat+sat]++;
351 (*lData)[nStep2Sat+light]++;
353 (*lData)[nNumIndex]++;
373 int ux,
int uy,
int lx,
int ly)
385 histo -= mHists_[ly-1][ux-1];
386 histo -= mHists_[uy-1][lx-1];
387 histo += mHists_[uy-1][ux-1];
389 else if(uy==0 && ux >0)
391 histo -= mHists_[ly-1][ux-1];
393 else if(ux==0 && uy >0){
394 histo -= mHists_[uy-1][lx-1];
396 int nBinwidth = 256/nBinsize_;
397 int nBinwidthSat= 256/nBinsizeSat_;
399 int nBinwidthsq = nBinwidth*nBinwidthSat;
400 int nBinCount = histo[nBinwidthsq+nBinwidth];
410 for(
int x=0;x<histo.
size()-1;x++){
411 normHisto[x]= (double)((
double) histo[x] / nBinCount);
414 normHisto[histo.
size()-1] = histo[histo.
size()-1];
417 for(
int i=0;i<nBinwidth;i++){
419 dist += sqrt(((
double)normHisto[nBinwidthsq+i])*m_cLData[i]);
422 for(
int j=0;j<nBinwidthSat;j++){
423 dist += sqrt((normHisto[i*nBinwidthSat+j])*m_cHSData[i][j]);
430 dist = exp(-nLambda_*(1-dist));
444 int ux1,
int uy1,
int lx1,
int ly1,
446 int ux2,
int uy2,
int lx2,
int ly2,
449 double sim1 = CalcSimilarity(chist1,ux1,uy1,lx1,ly1);
450 double sim2 = CalcSimilarity(chist2,ux2,uy2,lx2,ly2);
451 return (1.0-weightSecond)*sim1 + weightSecond*sim2;
463 os <<
" D = B + C - A\n";
464 os <<
"A: "<<mHists_[y-1][x-1]<<endl
465 <<
"B: "<<mHists_[y-1][x]<<endl
466 <<
"C: "<<mHists_[y][x-1]<<endl
467 <<
"D: "<<mHists_[y][x]<<endl;
468 os <<
" D = B + C - A\n";
std::vector< std::vector< double > > GetHist() const
return the histogram with H&S values
void SetLambda(int lambda)
sets Lambda, which is used to calculate the dist in CalcSimilarity
HSL, similar to HSV but space is a double tipped cone.
IntegralHistogram()
This class creates an IntegralHistogram in the HSL color space.
std::vector< double > GetHistL() const
return the L-values of the HSLcolorspace that are <MINSAT in the ROI
unsigned int GetWidth() const
void Clear()
Deletes ALL current Histogram information.
unsigned int GetHeight() const
double CalcSimilarity(ColorHistogram< unsigned char > &chist, int ux, int uy, int lx, int ly)
Calculates the Bhattacharyya similarity Coeiffient^2 which is the distance or difference of 2 colorhi...
void SetMinSat(int minsat)
set minsat_, which defines the minimum saturation
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
enum EColorModel GetColorModel() const
void SetBinSize(int binsize)
set the binsize (must be divideable by 2pown)
void SetExpDist(bool expdist)
sets expDist_ true or false, used to calculate the dist in CalcSimilarity
void Dump(std::ostream &os, int y, int x)
dumps information on histogram
int GenerateIntegralHist(BIAS::Image< unsigned char > &image, int nBinsize)
calcluates the histogram from the picture and fills the data structs
class TimeMeasure contains functions for timing real time and cpu time.
int GenerateIntegralHistDiffBin(BIAS::Image< unsigned char > &image, int nBinsizeHue, int nBinsizeSat)
calcluates the histogram from the picture and fills the data structs
void Fill(const T &scalar)
fills complete Vector with scalar value
Vector< int > GetHistogram(int ux, int uy, int lx, int ly)
Get Histogram.