How to detect star's center with sub-pixel accuracy

Discussions on extending SharpCap using the built in Python scripting functionality
Post Reply
User avatar
Posts: 1002
Joined: Sat Jul 08, 2017 2:37 pm
Location: New York

How to detect star's center with sub-pixel accuracy

Post by oopfan »

Hi Robin,

For years I've been using the following code to detect a star's center:

Code: Select all

from SharpCap.ImageProcessing import OpenCVStarDetector
from System.Drawing import Bitmap

gaussianBlur = 0.8
path = "C:\Users\Brian\Desktop\pec-learn\capture.png"

ocvsd = OpenCVStarDetector(2, 20, 10, gaussian_blur)
bm = Bitmap(path)
stars = ocvsd.Detect(bm)
star = stars[0]
xcenter = star.BoundingBox.X + 0.5 * star.BoundingBox.Width
ycenter = star.BoundingBox.Y + 0.5 * star.BoundingBox.Height
Now that I am a user of PHD2, I see the utility of calculating the position of a star with sub-pixel accuracy. However, star.BoundingBox refers to whole pixels, not fractions.

Is there another API that supports this?

User avatar
Site Admin
Posts: 6667
Joined: Sat Feb 11, 2017 3:52 pm
Location: Vale of the White Horse, UK

Re: How to detect star's center with sub-pixel accuracy

Post by admin »

Hi Brian,

yes, you can use star.Position (actually star.Position.X and star.Position.Y) to get the sub-pixel position of the star's center of brightness.

How accurate it is at the sub-pixel level is arguable - although the maths is easy to calculate the center of brightness, you need to remove the background brightness from the image data first, and working out the correct background level is an estimate at best. It will definitely be better than the center of the bounding box though. Probably good to 0.1px in most cases.


Post Reply