37 if (x<fX0 || x>=fX1 || y<fY0 || y>=fY1)
40 if (fCount>fLimitingSize)
44 float val = fImg[y*fW+x];
58 rc[0] = FindCluster(x+1, y );
59 rc[1] = FindCluster(x, y+1);
60 rc[2] = FindCluster(x-1, y );
61 rc[3] = FindCluster(x, y-1);
63 for (
int i=0;
i<4;
i++)
75 ClusterFinder(uint8_t *img, uint32_t w, uint32_t h) : fImg(0), fLimitingSize(999)
85 fImg =
new uint8_t[fW*fH];
87 memcpy(fImg, img, fW*fH);
94 Double_t
GetSumX()
const {
return fSumX; }
95 Double_t
GetSumY()
const {
return fSumY; }
107 return FindCluster(x, y);
110 void SetRange(int32_t x0=0, int32_t y0=0, int32_t x1=0, int32_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)
125 for (int32_t x=fX0; x<fX1; x++)
126 for (int32_t y=fY0; y<fY1; y++)
128 const uint8_t &b = fImg[y*fW+x];
132 const float mag = FindClusterAt(x, y);
135 cout <<
"ERROR - Spot with Size>999 detected..." << endl;
139 if (mag>0 && fCount>4)
140 leds.push_back(
Led(fSumX/mag, fSumY/mag, 0, mag));
148 const int x2,
const int y2,
156 const int x = (int)(px+.5);
157 const int y = (int)(py+.5);
158 const int m = (int)(mag);
160 DrawBox(x-8, y, x-5, y, m);
161 DrawBox(x, y+5, x, y+8, m);
162 DrawBox(x+5, y, x+8, y, m);
163 DrawBox(x, y-8, x, y-5, m);
179 const int x = (int)(led.
GetX()+.5);
180 const int y = (int)(led.
GetY()+.5);
182 MarkPoint(x, y, 0xff);
202 DrawCircle(l.
GetX(), l.
GetY(), r, col);
207 DrawHexagon(l.
GetX(), l.
GetY(), r, col);
215 uint8_t *s = (uint8_t*)fImg;
216 const uint8_t *e0 = s+fW*fH;
223 const uint8_t *e = s+fH-offset;
247 const int boxx,
const int boxy,
248 float &mx,
float &my,
unsigned int &sum)
const 254 for (
int dx=x-boxx; dx<x+boxx+1; dx++)
255 for (
int dy=y-boxy; dy<y+boxy+1; dy++)
257 const uint8_t &m = fImg[dy*fW+dx];
264 mx = (float)sumx/sum;
265 my = (float)sumy/sum;
267 return (
int)my*fW + (int)mx;
274 return GetMeanPosition(x, y, boxx, boxy, mx, my, sum);
278 const int boxx,
const int boxy,
279 float &mx,
float &my,
unsigned int &sum)
const 284 int x0 = max(x-boxx+1, 0);
285 int y0 = max(y-boxy+1, 0);
287 int x1 = min(x+boxx+1-1, fW);
288 int y1 = min(y+boxy+1-1, fH);
294 for (
int dx=x0; dx<x1; dx++)
296 for (
int dy=y0; dy<y1; dy++)
298 const unsigned int sumloc =
299 fImg[(dy+0)*fW + (dx-1)] +
300 fImg[(dy+0)*fW + (dx+1)] +
301 fImg[(dy+1)*fW + dx] +
302 fImg[(dy+0)*fW + dx] +
303 fImg[(dy-1)*fW + dx];
325 sum = (int)(mag+0.5);
327 return (
int)my*fW + (int)mx;
331 const int boxx,
const int boxy)
const 335 return GetMeanPositionBox(x, y, boxx, boxy, mx, my, sum);
341 Execute(leds, xc, yc, bright);
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);
351 const int wx = x1-x0;
352 const int hy = y1-y0;
357 for (
int x=x0; x<x1; x++)
358 for (
int y=y0; y<y1; y++)
360 uint8_t &b = fImg[y*fW+x];
377 const double sdev = sqrt(sq-sum*sum);
378 const uint8_t max = sum+fCut*sdev>254 ? 254 : (uint8_t)(sum+fCut*sdev);
384 for (
int x=x0; x<x1; x++)
385 for (
int y=y0; y<y1; y++)
387 uint8_t &b = fImg[y*fW+x];
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);
414 const double sqrt2 = sqrt(2.);
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);
430 for (
int x=xa; x<xb; x++)
431 for (
int y=ya; y<yb; y++)
433 if (x>=x0 && x<x1 && y>=y0 && y<y1)
436 uint8_t &b = fImg[y*fW+x];
447 const double sdev = sqrt(sq-sum*sum);
448 const uint8_t max = sum+fCut*sdev>254 ? 254 : (uint8_t)(sum+fCut*sdev);
455 for (
int x=x0; x<x1; x++)
456 for (
int y=y0; y<y1; y++)
458 uint8_t &b = fImg[y*fW+x];
468 for (
int x=xa; x<xb; x+=2)
473 for (
int y=ya; y<yb; y+=2)
490 int pos = box ? GetMeanPositionBox(xc, yc, fBoxX-1, fBoxY-1, mx, my, mag)
491 : GetMeanPosition(xc, yc, fBoxX-1, fBoxY-1, mx, my, mag);
493 if (pos<0 || pos>=fW*fH || fImg[pos]<sum+fCut*sdev)
499 leds.push_back(
Led(mx, my, 0, -2.5*log10((
float)mag)+13.7));
505 GetMinMax(25, &min, &max);
507 if (min==max || max-min>230)
510 const float scale = 255./(max-min);
513 const uint8_t *e = fImg+fW*fH;
527 *b = (uint8_t)((*b-min)*scale);
float FindCluster(int32_t x, int32_t y)
static void DrawHexagon(UChar_t *buf, int w, int h, Float_t x, Float_t y, Float_t r, UChar_t col, Int_t style=1)
int GetMeanPositionBox(const int x, const int y, const int boxx, const int boxy) const
void MarkPoint(const Led &led) const
void Execute(std::vector< Led > &leds, int xc, int yc, double &bright) const
uint32_t GetCount() const
float FindClusterAt(int32_t x, int32_t y)
void DrawBox(const int x1, const int y1, const int x2, const int y2, const int col) const
void SetLimitingSize(uint32_t lim)
void SetRange(int32_t x0=0, int32_t y0=0, int32_t x1=0, int32_t y1=0)
void FindCluster(vector< Led > &leds, int32_t x0=0, int32_t y0=0, int32_t x1=0, int32_t y1=0)
void DrawHexagon(float cx, float cy, float r, uint8_t col=0x40) const
void GetMinMax(const int offset, uint8_t *min, uint8_t *max) const
void DrawCircle(float cx, float cy, float r, uint8_t col=0x40) const
ClusterFinder(uint8_t *img, uint32_t w, uint32_t h)
static void DrawCircle(UChar_t *buf, int w, int h, Float_t x, Float_t y, Float_t r, UChar_t col)
void FindStar(std::vector< Led > &leds, int xc, int yc, bool circle=false) const
int GetMeanPosition(const int x, const int y, const int boxx, const int boxy) const
static void DrawBox(UChar_t *buf, int w, int h, Float_t x1, Float_t y1, Float_t x2, Float_t y2, UChar_t col, Int_t style=1)