Changeset 18621 for trunk/FACT++/drive/FilterLed.cc
- Timestamp:
- 09/18/16 14:46:35 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/drive/FilterLed.cc
r18618 r18621 5 5 #include <iostream> // cout 6 6 7 #include <TMath.h>8 9 7 #include "Led.h" 10 #include "Leds.h"11 8 #include "Ring.h" 12 9 13 #include "MGMap.h" 14 15 ClassImp(FilterLed); 10 #include "MGImage.h" 16 11 17 12 using namespace std; … … 20 15 { 21 16 private: 22 byte*fImg;23 24 UInt_t fW;25 UInt_t fH;26 27 Int_t fX0;28 Int_t fX1;29 30 Int_t fY0;31 Int_t fY1;32 33 UInt_t fLimitingSize;34 35 UInt_t fCount;36 Float_t fSumX;37 Float_t fSumY;38 39 Float_t FindCluster(Int_t x, Int_t y)17 uint8_t *fImg; 18 19 uint32_t fW; 20 uint32_t fH; 21 22 int32_t fX0; 23 int32_t fX1; 24 25 int32_t fY0; 26 int32_t fY1; 27 28 uint32_t fLimitingSize; 29 30 uint32_t fCount; 31 float fSumX; 32 float fSumY; 33 34 float FindCluster(int32_t x, int32_t y) 40 35 { 41 36 // if edge is touched stop finding cluster … … 47 42 48 43 // get the value 49 Float_t val = fImg[y*fW+x];44 float val = fImg[y*fW+x]; 50 45 51 46 // if its empty we have found the border of the cluster … … 60 55 fCount++; 61 56 62 Float_t rc[4];57 float rc[4]; 63 58 rc[0] = FindCluster(x+1, y ); 64 59 rc[1] = FindCluster(x, y+1); … … 78 73 79 74 public: 80 ClusterFinder( byte *img, UInt_t w, UInt_t h) : fImg(0), fLimitingSize(999)75 ClusterFinder(uint8_t *img, uint32_t w, uint32_t h) : fImg(0), fLimitingSize(999) 81 76 { 82 77 fW = w; … … 88 83 fY1 = fH; 89 84 90 fImg = new byte[fW*fH];85 fImg = new uint8_t[fW*fH]; 91 86 92 87 memcpy(fImg, img, fW*fH); … … 100 95 Double_t GetSumY() const { return fSumY; } 101 96 102 UInt_t GetCount() const { return fCount; }103 104 void SetLimitingSize( UInt_t lim) { fLimitingSize=lim; }105 106 Float_t FindClusterAt(Int_t x, Int_t y)97 uint32_t GetCount() const { return fCount; } 98 99 void SetLimitingSize(uint32_t lim) { fLimitingSize=lim; } 100 101 float FindClusterAt(int32_t x, int32_t y) 107 102 { 108 103 fCount = 0; … … 113 108 } 114 109 115 void SetRange( Int_t x0=0, Int_t y0=0, Int_t x1=0, Int_t y1=0)110 void SetRange(int32_t x0=0, int32_t y0=0, int32_t x1=0, int32_t y1=0) 116 111 { 117 112 fX0 = x0; … … 121 116 } 122 117 123 void FindCluster( Leds &leds, Int_t x0=0, Int_t y0=0, Int_t x1=0, Int_t y1=0)118 void FindCluster(vector<Led> &leds, int32_t x0=0, int32_t y0=0, int32_t x1=0, int32_t y1=0) 124 119 { 125 120 fX0 = x0; … … 128 123 fY1 = y1==0?fH:y1; 129 124 130 for ( Int_t x=fX0; x<fX1; x++)131 for ( Int_t y=fY0; y<fY1; y++)125 for (int32_t x=fX0; x<fX1; x++) 126 for (int32_t y=fY0; y<fY1; y++) 132 127 { 133 const byte&b = fImg[y*fW+x];128 const uint8_t &b = fImg[y*fW+x]; 134 129 if (b==0) 135 130 continue; 136 131 137 const Float_t mag = FindClusterAt(x, y);132 const float mag = FindClusterAt(x, y); 138 133 if (fCount>999) 139 134 { … … 142 137 } 143 138 144 if (mag>0 && fCount> 6)145 leds. Add(fSumX/mag, fSumY/mag, 0, 0, mag);139 if (mag>0 && fCount>4) 140 leds.push_back(Led(fSumX/mag, fSumY/mag, 0, mag)); 146 141 } 147 leds.Compress();142 //leds.Compress(); 148 143 } 149 144 }; … … 154 149 const int col) const 155 150 { 156 MG Map::DrawBox(fImg, 768, 576, x1, y1, x2, y2, col);157 } 158 159 void FilterLed::MarkPoint( Float_t px, Float_t py, Float_t mag) const151 MGImage::DrawBox(fImg, 768, 576, x1, y1, x2, y2, col); 152 } 153 154 void FilterLed::MarkPoint(float px, float py, float mag) const 160 155 { 161 156 const int x = (int)(px+.5); … … 172 167 { 173 168 /* 174 Int_t M = (int)(log(led.GetMag())*20);169 int32_t M = (int)(log(led.GetMag())*20); 175 170 176 171 cout << led.GetMag() << endl; … … 188 183 } 189 184 190 void FilterLed::DrawCircle(float cx, float cy, float r, bytecol) const191 { 192 MG Map::DrawCircle(fImg, 768, 576, cx, cy, r, col);193 } 194 195 void FilterLed::DrawHexagon(float cx, float cy, float r, bytecol) const196 { 197 MG Map::DrawHexagon(fImg, 768, 576, cx, cy, r, col);198 } 199 200 void FilterLed::DrawCircle(const Ring &l, bytecol) const185 void FilterLed::DrawCircle(float cx, float cy, float r, uint8_t col) const 186 { 187 MGImage::DrawCircle(fImg, 768, 576, cx, cy, r, col); 188 } 189 190 void FilterLed::DrawHexagon(float cx, float cy, float r, uint8_t col) const 191 { 192 MGImage::DrawHexagon(fImg, 768, 576, cx, cy, r, col); 193 } 194 195 void FilterLed::DrawCircle(const Ring &l, uint8_t col) const 201 196 { 202 197 DrawCircle(l.GetX(), l.GetY(), l.GetR(), col); 203 198 } 204 199 205 void FilterLed::DrawCircle(const Ring &l, double r, bytecol) const200 void FilterLed::DrawCircle(const Ring &l, double r, uint8_t col) const 206 201 { 207 202 DrawCircle(l.GetX(), l.GetY(), r, col); 208 203 } 209 204 210 void FilterLed::DrawHexagon(const Ring &l, double r, bytecol) const205 void FilterLed::DrawHexagon(const Ring &l, double r, uint8_t col) const 211 206 { 212 207 DrawHexagon(l.GetX(), l.GetY(), r, col); 213 208 } 214 209 215 void FilterLed::GetMinMax(const int offset, byte *min, byte*max) const210 void FilterLed::GetMinMax(const int offset, uint8_t *min, uint8_t *max) const 216 211 { 217 212 *min = fImg[0]; 218 213 *max = fImg[0]; 219 214 220 byte *s = (byte*)fImg;221 const byte*e0 = s+fW*fH;215 uint8_t *s = (uint8_t*)fImg; 216 const uint8_t *e0 = s+fW*fH; 222 217 223 218 // … … 226 221 while (s<e0) 227 222 { 228 const byte*e = s+fH-offset;223 const uint8_t *e = s+fH-offset; 229 224 s += offset; 230 225 … … 260 255 for (int dy=y-boxy; dy<y+boxy+1; dy++) 261 256 { 262 const byte&m = fImg[dy*fW+dx];257 const uint8_t &m = fImg[dy*fW+dx]; 263 258 264 259 sumx += m*dx; … … 287 282 // Improved algorithm: 288 283 // 1. Look for the largest five-pixel-cross signal inside the box 289 int x0 = TMath::Max(x-boxx+1, 0);290 int y0 = TMath::Max(y-boxy+1, 0);291 292 int x1 = TMath::Min(x+boxx+1-1, fW);293 int y1 = TMath::Min(y+boxy+1-1, fH);284 int x0 = max(x-boxx+1, 0); 285 int y0 = max(y-boxy+1, 0); 286 287 int x1 = min(x+boxx+1-1, fW); 288 int y1 = min(y+boxy+1-1, fH); 294 289 295 290 int maxx=0; … … 323 318 find.SetRange(x0, y0, x1, y1); 324 319 325 const Float_t mag = find.FindClusterAt(maxx, maxy);320 const float mag = find.FindClusterAt(maxx, maxy); 326 321 327 322 mx = find.GetSumX()/mag; … … 341 336 } 342 337 343 void FilterLed::ExecuteAndMark(Leds &leds, int xc, int yc) const 344 { 345 const Int_t first = leds.GetEntriesFast(); 346 347 Execute(leds, xc, yc); 348 349 // Mark Stars in image 350 for (int i=first; i<leds.GetEntriesFast(); i++) 351 MarkPoint(leds(i)); 352 } 353 354 355 void FilterLed::ExecuteAndMark(Leds &leds, int xc, int yc, double &bright) const 356 { 357 const Int_t first = leds.GetEntriesFast(); 358 359 Execute(leds, xc, yc, bright); 360 361 // Mark Stars in image 362 for (int i=first; i<leds.GetEntriesFast(); i++) 363 MarkPoint(leds(i)); 364 } 365 366 void FilterLed::Execute(int xc, int yc) const 367 { 368 Leds leds; 369 ExecuteAndMark(leds, xc, yc); 370 } 371 372 void FilterLed::Execute(Leds &leds, int xc, int yc) const 338 void FilterLed::Execute(vector<Led> &leds, int xc, int yc) const 373 339 { 374 340 double bright; … … 376 342 } 377 343 378 void FilterLed::Execute( Leds&leds, int xc, int yc, double &bright) const379 { 380 const int x0 = TMath::Max(xc-fBoxX, 0);381 const int y0 = TMath::Max(yc-fBoxY, 0);382 const int x1 = TMath::Min(xc+fBoxX, fW);383 const int y1 = TMath::Min(yc+fBoxY, fH);344 void FilterLed::Execute(vector<Led> &leds, int xc, int yc, double &bright) const 345 { 346 const int x0 = max(xc-fBoxX, 0); 347 const int y0 = max(yc-fBoxY, 0); 348 const int x1 = min(xc+fBoxX, fW); 349 const int y1 = min(yc+fBoxY, fH); 384 350 385 351 const int wx = x1-x0; … … 392 358 for (int y=y0; y<y1; y++) 393 359 { 394 byte&b = fImg[y*fW+x];360 uint8_t &b = fImg[y*fW+x]; 395 361 396 362 // Skip saturating pixels … … 410 376 // 254 because b<=max and not b<max 411 377 const double sdev = sqrt(sq-sum*sum); 412 const byte max = sum+fCut*sdev>254 ? 254 : (byte)(sum+fCut*sdev);378 const uint8_t max = sum+fCut*sdev>254 ? 254 : (uint8_t)(sum+fCut*sdev); 413 379 414 380 // … … 419 385 for (int y=y0; y<y1; y++) 420 386 { 421 byte&b = fImg[y*fW+x];387 uint8_t &b = fImg[y*fW+x]; 422 388 if (b<=max) 423 389 b = 0; … … 428 394 } 429 395 430 void FilterLed::FindStar( Leds&leds, int xc, int yc, bool box) const396 void FilterLed::FindStar(vector<Led> &leds, int xc, int yc, bool box) const 431 397 { 432 398 // fBox: radius of the inner (signal) box … … 436 402 // Define inner box in which to search the signal 437 403 // 438 const int x0 = TMath::Max(xc-fBoxX, 0);439 const int y0 = TMath::Max(yc-fBoxY, 0);440 const int x1 = TMath::Min(xc+fBoxX, fW);441 const int y1 = TMath::Min(yc+fBoxY, fH);404 const int x0 = max(xc-fBoxX, 0); 405 const int y0 = max(yc-fBoxY, 0); 406 const int x1 = min(xc+fBoxX, fW); 407 const int y1 = min(yc+fBoxY, fH); 442 408 443 409 // … … 448 414 const double sqrt2 = sqrt(2.); 449 415 450 const int xa = TMath::Max(xc-TMath::Nint(fBoxX*sqrt2), 0);451 const int ya = TMath::Max(yc-TMath::Nint(fBoxY*sqrt2), 0);452 const int xb = TMath::Min(xc+TMath::Nint(fBoxX*sqrt2), fW);453 const int yb = TMath::Min(yc+TMath::Nint(fBoxY*sqrt2), fH);416 const int xa = max(xc-(int)nearbyint(fBoxX*sqrt2), 0); 417 const int ya = max(yc-(int)nearbyint(fBoxY*sqrt2), 0); 418 const int xb = min(xc+(int)nearbyint(fBoxX*sqrt2), fW); 419 const int yb = min(yc+(int)nearbyint(fBoxY*sqrt2), fH); 454 420 455 421 // … … 468 434 continue; 469 435 470 byte&b = fImg[y*fW+x];436 uint8_t &b = fImg[y*fW+x]; 471 437 472 438 sum += b; … … 480 446 // 254 because b<=max and not b<max 481 447 const double sdev = sqrt(sq-sum*sum); 482 const byte max = sum+fCut*sdev>254 ? 254 : (byte)(sum+fCut*sdev);448 const uint8_t max = sum+fCut*sdev>254 ? 254 : (uint8_t)(sum+fCut*sdev); 483 449 484 450 // … … 490 456 for (int y=y0; y<y1; y++) 491 457 { 492 byte&b = fImg[y*fW+x];458 uint8_t &b = fImg[y*fW+x]; 493 459 if (b<=max) 494 460 b = 0; … … 531 497 // cout << "Sum/n = " << sum << "/" << n << " = " << (n==0?0:mag/n) << endl; 532 498 533 leds. Add(mx, my, 0, 0, -2.5*log10((float)mag)+13.7);499 leds.push_back(Led(mx, my, 0, -2.5*log10((float)mag)+13.7)); 534 500 } 535 501 536 502 void FilterLed::Stretch() const 537 503 { 538 bytemin, max;504 uint8_t min, max; 539 505 GetMinMax(25, &min, &max); 540 506 … … 544 510 const float scale = 255./(max-min); 545 511 546 byte*b = fImg;547 const byte*e = fImg+fW*fH;512 uint8_t *b = fImg; 513 const uint8_t *e = fImg+fW*fH; 548 514 549 515 while (b<e) … … 559 525 continue; 560 526 } 561 *b = ( byte)((*b-min)*scale);527 *b = (uint8_t)((*b-min)*scale); 562 528 b++; 563 529 }
Note:
See TracChangeset
for help on using the changeset viewer.