summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasem Mutlaq <mutlaqja@ikarustech.com>2016-08-14 10:55:08 (GMT)
committerJasem Mutlaq <mutlaqja@ikarustech.com>2016-08-14 10:55:08 (GMT)
commitc9e0cfca0dcc378e9be3eda567ec7801e245f16b (patch)
tree81d9c84c4da56a8c18ba19e6c126c8f895f9b8e1
parentfd5be743f643e3ae087eb626c644a303bdc2244e (diff)
Adding preliminary testing algorithm for 1 star bounded detection
-rw-r--r--kstars/fitsviewer/fitsdata.cpp83
-rw-r--r--kstars/fitsviewer/fitsdata.h1
-rw-r--r--kstars/fitsviewer/fitsview.cpp8
3 files changed, 90 insertions, 2 deletions
diff --git a/kstars/fitsviewer/fitsdata.cpp b/kstars/fitsviewer/fitsdata.cpp
index 6f229e8..d92531c 100644
--- a/kstars/fitsviewer/fitsdata.cpp
+++ b/kstars/fitsviewer/fitsdata.cpp
@@ -554,6 +554,85 @@ bool FITSData::checkCollision(Edge* s1, Edge*s2)
return false;
}
+int FITSData::findOneStar(const QRectF &boundary)
+{
+ int subX = boundary.x();
+ int subY = boundary.y();
+ int subW = subX + boundary.width();
+ int subH = subY + boundary.height();
+
+ float massX=0, massY=0, totalMass=0;
+
+ double threshold = stats.median[0] + stats.stddev[0];
+
+ for (int y=subY; y < subH; y++)
+ {
+ for (int x=subX; x < subW; x++)
+ {
+ float pixel = image_buffer[x+y*stats.width];
+ if (pixel > threshold)
+ {
+ totalMass += pixel;
+ massX += x * pixel;
+ massY += y * pixel;
+ }
+ }
+ }
+
+ qDebug() << "Weighted Center is X: " << massX/totalMass << " Y: " << massY/totalMass;
+
+ Edge *center = new Edge;
+ center->width = 10;
+ center->x = massX/totalMass + 0.5;
+ center->y = massY/totalMass + 0.5;
+ center->HFR = 1;
+
+ // Maximum Radius
+ int maxR = qMin(subW-1, subH-1) / 2;
+
+ // Critical threshold
+ double critical_threshold = threshold * 0.7;
+ double running_threshold = threshold;
+
+ while (running_threshold >= critical_threshold)
+ {
+ for (int r=maxR; r > 2; r--)
+ {
+ int pass=0, fail=0;
+
+ for (float theta=0; theta < 2*M_PI; theta += (2*M_PI)/10.0)
+ {
+ int testX = center->x + cos(theta) * r;
+ int testY = center->y + sin(theta) * r;
+
+ // if out of bound, break;
+ if (testX < subX || testX > subW || testY < subY || testY > subH)
+ break;
+
+ if (image_buffer[testX + testY * stats.width] > running_threshold)
+ pass++;
+ else if (fail++ > 3)
+ break;
+ }
+
+ qDebug() << "Testing for radius " << r << " passes # " << pass << " @ threshold " << running_threshold;
+ if (pass >= 9)
+ {
+ center->width = r*2;
+ running_threshold=0;
+ break;
+ }
+ }
+
+ // Increase threshold fuzziness by 10%
+ running_threshold -= running_threshold * 0.1;
+ }
+
+ starCenters.append(center);
+
+ return starCenters.size();
+
+}
/*** Find center of stars and calculate Half Flux Radius */
void FITSData::findCentroid(const QRectF &boundary, int initStdDev, int minEdgeWidth)
@@ -638,6 +717,10 @@ void FITSData::findCentroid(const QRectF &boundary, int initStdDev, int minEdgeW
}
else
{
+ // Only find a single star within the boundary
+ //findOneStar(boundary);
+ //return;
+
subX = boundary.x();
subY = boundary.y();
subW = subX + boundary.width();
diff --git a/kstars/fitsviewer/fitsdata.h b/kstars/fitsviewer/fitsdata.h
index c287d7b..765d214 100644
--- a/kstars/fitsviewer/fitsdata.h
+++ b/kstars/fitsviewer/fitsdata.h
@@ -134,6 +134,7 @@ public:
int findStars(const QRectF &boundary = QRectF(), bool force=false);
void findCentroid(const QRectF &boundary = QRectF(), int initStdDev=MINIMUM_STDVAR, int minEdgeWidth=MINIMUM_PIXEL_RANGE);
void getCenterSelection(int *x, int *y);
+ int findOneStar(const QRectF &boundary);
// Half Flux Radius
Edge * getMaxHFRStar() { return maxHFRStar;}
diff --git a/kstars/fitsviewer/fitsview.cpp b/kstars/fitsviewer/fitsview.cpp
index 977bab3..90d9310 100644
--- a/kstars/fitsviewer/fitsview.cpp
+++ b/kstars/fitsviewer/fitsview.cpp
@@ -785,14 +785,18 @@ void FITSView::toggleStars(bool enable)
qApp->processEvents();
int count = -1;
- /*if (trackingBoxEnabled)
+ if (trackingBoxEnabled)
{
count = image_data->findStars(trackingBox, trackingBoxUpdated);
trackingBoxUpdated=false;
}
- else*/
+ else
count = image_data->findStars();
+
+ //QRectF boundary(0,0, image_data->getWidth(), image_data->getHeight());
+ //count = image_data->findOneStar(boundary);
+
if (count >= 0 && isVisible())
emit newStatus(i18np("1 star detected.", "%1 stars detected.", count), FITS_MESSAGE);
QApplication::restoreOverrideCursor();