FACT++  1.0
void FilterLed::FindStar ( std::vector< Led > &  leds,
int  xc,
int  yc,
bool  circle = false 
) const

Definition at line 396 of file FilterLed.cc.

References mag.

Referenced by MStarguider::ProcessFrame(), and SetCut().

397 {
398  // fBox: radius of the inner (signal) box
399  // Radius of the outer box is fBox*sqrt(2)
400 
401  //
402  // Define inner box in which to search the signal
403  //
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);
408 
409  //
410  // Define outer box (excluding inner box) having almost
411  // the same number of pixels in which the background
412  // is calculated
413  //
414  const double sqrt2 = sqrt(2.);
415 
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);
420 
421  //
422  // Calculate average and sdev for a square
423  // excluding the inner part were we expect
424  // the signal to be.
425  //
426  double sum = 0;
427  double sq = 0;
428 
429  int n=0;
430  for (int x=xa; x<xb; x++)
431  for (int y=ya; y<yb; y++)
432  {
433  if (x>=x0 && x<x1 && y>=y0 && y<y1)
434  continue;
435 
436  uint8_t &b = fImg[y*fW+x];
437 
438  sum += b;
439  sq += b*b;
440  n++;
441  }
442 
443  sum /= n;
444  sq /= n;
445 
446  // 254 because b<=max and not b<max
447  const double sdev = sqrt(sq-sum*sum);
448  const uint8_t max = sum+fCut*sdev>254 ? 254 : (uint8_t)(sum+fCut*sdev);
449 
450  //
451  // clean image from noise
452  // (FIXME: A lookup table could accelerate things...
453  //
454  n=0;
455  for (int x=x0; x<x1; x++)
456  for (int y=y0; y<y1; y++)
457  {
458  uint8_t &b = fImg[y*fW+x];
459  if (b<=max)
460  b = 0;
461  else
462  n++;
463  }
464 
465  //
466  // Mark the background region
467  //
468  for (int x=xa; x<xb; x+=2)
469  {
470  fImg[ya*fW+x]=0xf0;
471  fImg[yb*fW+x]=0xf0;
472  }
473  for (int y=ya; y<yb; y+=2)
474  {
475  fImg[y*fW+xa]=0xf0;
476  fImg[y*fW+xb]=0xf0;
477  }
478 
479  //
480  // Check if any pixel found...
481  //
482  if (n<5)
483  return;
484 
485  //
486  // Get the mean position of the star
487  //
488  float mx, my;
489  unsigned int mag;
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);
492 
493  if (pos<0 || pos>=fW*fH || fImg[pos]<sum+fCut*sdev)
494  return;
495 
496  // cout << "Mean=" << sum << " SDev=" << sdev << " : ";
497  // cout << "Sum/n = " << sum << "/" << n << " = " << (n==0?0:mag/n) << endl;
498 
499  leds.push_back(Led(mx, my, 0, -2.5*log10((float)mag)+13.7));
500 }
int GetMeanPositionBox(const int x, const int y, const int boxx, const int boxy) const
Definition: FilterLed.cc:330
int fH
Definition: FilterLed.h:14
float mag
Definition: HeadersSQM.h:89
Definition: Led.h:8
int fBoxY
Definition: FilterLed.h:16
int fBoxX
Definition: FilterLed.h:15
float fCut
Definition: FilterLed.h:17
int fW
Definition: FilterLed.h:13
uint8_t * fImg
Definition: FilterLed.h:12
int GetMeanPosition(const int x, const int y, const int boxx, const int boxy) const
Definition: FilterLed.cc:270

+ Here is the caller graph for this function: