81 std::vector<unsigned char> *rowMax =
nullptr) {
82 unsigned long totalMag = 0;
84 long totalPixels = imageHeight * imageWidth;
85 if (rowMax !=
nullptr) rowMax->assign(imageHeight, 0);
86 for (
int y = 0; y < imageHeight; y++) {
87 const unsigned char *row = image + (long)y * imageWidth;
88 unsigned char brightest = 0;
89 for (
int x = 0; x < imageWidth; x++) {
91 brightest = std::max(brightest, row[x]);
93 if (rowMax !=
nullptr) (*rowMax)[y] = brightest;
96 for (
long i = 0; i < totalPixels; i++) {
100 return mean + (std * 5);
132 std::vector<Star> result;
134 std::vector<unsigned char> rowMax;
135 int cutoff =
BasicThreshold(image, imageWidth, imageHeight, &rowMax);
136 const int offsets[] = {1, -1, imageWidth, -imageWidth};
137 const long n = imageWidth * imageHeight;
138 std::vector<bool> visited(n,
false);
140 for (
int row = 0; row < imageHeight; row++) {
141 if (rowMax[row] < cutoff)
continue;
142 const long rowEnd = (long)(row + 1) * imageWidth;
143 for (
long i = (
long)row * imageWidth; i < rowEnd; i++) {
144 if (image[i] >= cutoff && !visited[i]) {
150 int centroidSize = 0;
151 std::vector<long> queue = {i};
154 while (!queue.empty()) {
155 long ind = queue.back();
158 long x = ind % imageWidth, y = ind / imageWidth;
159 if (x == 0 || x == imageWidth - 1 || y == 0 || y == imageHeight - 1) {
172 for (
int offset : offsets) {
173 long ni = ind + offset;
174 if (ni >= 0 && ni < n && std::abs((ni % imageWidth)-x) <= 1 && image[ni] >= cutoff && !visited[ni]) {
181 int xDiameter = (p.
xMax - p.
xMin) + 1;
182 int yDiameter = (p.
yMax - p.
yMin) + 1;
184 if (isValid && p.
magSum > 0) {
211void IWCoGHelper(
IWCoGParams *p,
long i,
unsigned char *image,
int imageWidth,
int imageHeight, std::vector<int> *starIndices) {
212 if (i >= 0 && i < imageWidth * imageHeight && image[i] >= p->
cutoff && p->
checkedIndices.count(i) == 0) {
214 if (i % imageWidth == 0 || i % imageWidth == imageWidth - 1 || i / imageWidth == 0 || i / imageWidth == imageHeight - 1) {
218 starIndices->push_back(i);
223 if (i % imageWidth > p->
xMax) {
224 p->
xMax = i % imageWidth;
225 }
else if (i % imageWidth < p->xMin) {
226 p->
xMin = i % imageWidth;
228 if (i / imageWidth > p->
yMax) {
229 p->
yMax = i / imageWidth;
230 }
else if (i / imageWidth < p->yMin) {
231 p->
yMin = i / imageWidth;
233 if (i % imageWidth != imageWidth - 1) {
234 IWCoGHelper(p, i + 1, image, imageWidth, imageHeight, starIndices);
236 if (i % imageWidth != 0) {
237 IWCoGHelper(p, i - 1, image, imageWidth, imageHeight, starIndices);
239 IWCoGHelper(p, i + imageWidth, image, imageWidth, imageHeight, starIndices);
240 IWCoGHelper(p, i - imageWidth, image, imageWidth, imageHeight, starIndices);
246 std::vector<Star> result;
248 for (
long i = 0; i < imageHeight * imageWidth; i++) {
252 std::vector<int> starIndices;
256 decimal yWeightedCoordMagSum = 0;
257 decimal xWeightedCoordMagSum = 0;
263 p.
xMax = i % imageWidth;
264 p.
xMin = i % imageWidth;
265 p.
yMax = i / imageWidth;
266 p.
yMin = i / imageWidth;
270 IWCoGHelper(&p, i, image, imageWidth, imageHeight, &starIndices);
277 for (
int j = 0; j < (int) starIndices.size(); j++) {
294 yWeightedCoordMagSum = 0;
295 xWeightedCoordMagSum = 0;
298 for (
long j = 0; j < (long)starIndices.size(); j++) {
300 decimal currXCoord = starIndices.at(j) % imageWidth;
301 decimal currYCoord = starIndices.at(j) / imageWidth;
304 xWeightedCoordMagSum += w * currXCoord *
DECIMAL(image[starIndices.at(j)]);
305 yWeightedCoordMagSum += w * currYCoord *
DECIMAL(image[starIndices.at(j)]);
306 weightedMagSum += w *
DECIMAL(image[starIndices.at(j)]);
308 decimal xTemp = xWeightedCoordMagSum / weightedMagSum;
309 decimal yTemp = yWeightedCoordMagSum / weightedMagSum;
311 change = abs(guessXCoord - xTemp) + abs(guessYCoord - yTemp);
void IWCoGHelper(IWCoGParams *p, long i, unsigned char *image, int imageWidth, int imageHeight, std::vector< int > *starIndices)