10 #include <unordered_map> 
   11 #include <unordered_set> 
   20     std::vector<Star> result;
 
   22     unsigned int randomSeed = 123456;
 
   23     for (
int i = 0; i < numStars; i++) {
 
   24         result.push_back(
Star(rand_r(&randomSeed) % imageWidth, rand_r(&randomSeed) % imageHeight, 
DECIMAL(10.0)));
 
   31 int BadThreshold(
unsigned char *image, 
int imageWidth, 
int imageHeight) {
 
   34     for (
long i = 0; i < imageHeight * imageWidth; i++) {
 
   37     return (((totalMag/(imageHeight * imageWidth)) + 1) * 15) / 10;
 
   43     long total = imageWidth * imageHeight;
 
   53     memset(histogram, 0, 
sizeof(
int)*256);
 
   55     for (
long i = 0; i < total; i++) {
 
   56         histogram[image[i]]++;
 
   58     for (
int i = 0; i < 256; i ++) {
 
   59         sum1 += i * histogram[i];
 
   61     for (
int i = 0; i < 256; i ++) {
 
   65         if (wB > 0 && wF > 0) {
 
   66             decimal mF = (sum1 - sumB) / wF;
 
   67             decimal val = wB * wF * ((sumB / wB) - mF) * ((sumB / wB) - mF);
 
   74         wB = wB + histogram[i];
 
   75         sumB = sumB + i * histogram[i];
 
   82     unsigned long totalMag = 0;
 
   84     long totalPixels = imageHeight * imageWidth;
 
   85     for (
long i = 0; i < totalPixels; i++) {
 
   88     decimal mean = totalMag / totalPixels;
 
   89     for (
long i = 0; i < totalPixels; i++) {
 
   93     return mean + (std * 5);
 
   98     unsigned long totalMag = 0;
 
  101     long totalPixels = imageHeight * imageWidth;
 
  102     for (
long i = 0; i < totalPixels; i++) {
 
  103         totalMag += image[i];
 
  104         sq_totalMag += image[i] * image[i];
 
  106     decimal mean = totalMag / totalPixels;
 
  107     decimal variance = (sq_totalMag / totalPixels) - (mean * mean);
 
  109     return mean + (std * 5);
 
  128     if (i >= 0 && i < imageWidth * imageHeight && image[i] >= p->
cutoff && p->
checkedIndices.count(i) == 0) {
 
  130         if (i % imageWidth == 0 || i % imageWidth == imageWidth - 1 || i / imageWidth == 0 || i / imageWidth == imageHeight - 1) {
 
  134         if (i % imageWidth > p->
xMax) {
 
  135             p->
xMax = i % imageWidth;
 
  136         } 
else if (i % imageWidth < p->xMin) {
 
  137             p->
xMin = i % imageWidth;
 
  139         if (i / imageWidth > p->
yMax) {
 
  140             p->
yMax = i / imageWidth;
 
  141         } 
else if (i / imageWidth < p->yMin) {
 
  142             p->
yMin = i / imageWidth;
 
  147         if (i % imageWidth != imageWidth - 1) {
 
  148             CogHelper(p, i + 1, image, imageWidth, imageHeight);
 
  150         if (i % imageWidth != 0) {
 
  151             CogHelper(p, i - 1, image, imageWidth, imageHeight);
 
  153         CogHelper(p, i + imageWidth, image, imageWidth, imageHeight);
 
  154         CogHelper(p, i - imageWidth, image, imageWidth, imageHeight);
 
  161     std::vector<Star> result;
 
  164     for (
long i = 0; i < imageHeight * imageWidth; i++) {
 
  174             p.
xMax = i % imageWidth;
 
  175             p.
xMin = i % imageWidth;
 
  176             p.
yMax = i / imageWidth;
 
  177             p.
yMin = i / imageWidth;
 
  182             CogHelper(&p, i, image, imageWidth, imageHeight);
 
  214 void IWCoGHelper(
IWCoGParams *p, 
long i, 
unsigned char *image, 
int imageWidth, 
int imageHeight, std::vector<int> *starIndices) {
 
  215     if (i >= 0 && i < imageWidth * imageHeight && image[i] >= p->
cutoff && p->
checkedIndices.count(i) == 0) {
 
  217         if (i % imageWidth == 0 || i % imageWidth == imageWidth - 1 || i / imageWidth == 0 || i / imageWidth == imageHeight - 1) {
 
  221         starIndices->push_back(i);
 
  226         if (i % imageWidth > p->
xMax) {
 
  227             p->
xMax = i % imageWidth;
 
  228         } 
else if (i % imageWidth < p->xMin) {
 
  229             p->
xMin = i % imageWidth;
 
  231         if (i / imageWidth > p->
yMax) {
 
  232             p->
yMax = i / imageWidth;
 
  233         } 
else if (i / imageWidth < p->yMin) {
 
  234             p->
yMin = i / imageWidth;
 
  236         if (i % imageWidth != imageWidth - 1) {
 
  237             IWCoGHelper(p, i + 1, image, imageWidth, imageHeight, starIndices);
 
  239         if (i % imageWidth != 0) {
 
  240             IWCoGHelper(p, i - 1, image, imageWidth, imageHeight, starIndices);
 
  242         IWCoGHelper(p, i + imageWidth, image, imageWidth, imageHeight, starIndices);
 
  243         IWCoGHelper(p, i - imageWidth, image, imageWidth, imageHeight, starIndices);
 
  249     std::vector<Star> result;
 
  251     for (
long i = 0; i < imageHeight * imageWidth; i++) {
 
  255             std::vector<int> starIndices; 
 
  259             decimal yWeightedCoordMagSum = 0;
 
  260             decimal xWeightedCoordMagSum = 0;
 
  266             p.
xMax = i % imageWidth;
 
  267             p.
xMin = i % imageWidth;
 
  268             p.
yMax = i / imageWidth;
 
  269             p.
yMin = i / imageWidth;
 
  273             IWCoGHelper(&p, i, image, imageWidth, imageHeight, &starIndices);
 
  280             for (
int j = 0; j < (int) starIndices.size(); j++) {
 
  297                 yWeightedCoordMagSum = 0;
 
  298                 xWeightedCoordMagSum = 0;
 
  301                 for (
long j = 0; j < (long)starIndices.size(); j++) {
 
  303                     decimal currXCoord = starIndices.at(j) % imageWidth;
 
  304                     decimal currYCoord = starIndices.at(j) / imageWidth;
 
  307                     xWeightedCoordMagSum += w * currXCoord * 
DECIMAL(image[starIndices.at(j)]);
 
  308                     yWeightedCoordMagSum += w * currYCoord * 
DECIMAL(image[starIndices.at(j)]);
 
  309                     weightedMagSum += w * 
DECIMAL(image[starIndices.at(j)]);
 
  311                 decimal xTemp = xWeightedCoordMagSum / weightedMagSum;
 
  312                 decimal yTemp = yWeightedCoordMagSum / weightedMagSum;
 
  314                 change = abs(guessXCoord - xTemp) + abs(guessYCoord - yTemp);
 
Stars Go(unsigned char *image, int imageWidth, int imageHeight) const override
Actually perform the centroid detection.
 
Stars Go(unsigned char *image, int imageWidth, int imageHeight) const override
Actually perform the centroid detection.
 
Stars Go(unsigned char *image, int imageWidth, int imageHeight) const override
Actually perform the centroid detection.
 
A "centroid" detected in an image.
 
#define DECIMAL_POW(base, power)
 
int OtsusThreshold(unsigned char *image, int imageWidth, int imageHeight)
 
int BadThreshold(unsigned char *image, int imageWidth, int imageHeight)
 
std::vector< Star > Stars
 
void IWCoGHelper(IWCoGParams *p, long i, unsigned char *image, int imageWidth, int imageHeight, std::vector< int > *starIndices)
 
void CogHelper(CentroidParams *p, long i, unsigned char *image, int imageWidth, int imageHeight)
 
int BasicThresholdOnePass(unsigned char *image, int imageWidth, int imageHeight)
 
int BasicThreshold(unsigned char *image, int imageWidth, int imageHeight)
 
std::unordered_set< int > checkedIndices
 
std::unordered_set< int > checkedIndices