-1

Here I have an image of two objects/stars: picture of two stars I have hundreds of images like this one, from NASA MAST Archive. (The corners are not stars, just errors, one star is on the top, the other one is on the bottom). What algorithm should I use to determine the number of objects (in this case stars) in one picture? For a human, it is pretty obvious that there are two objects, but I want to implement this detection in Python. For reference, here is a picture with one star only: Image of one star

(The pictures are produced from FITS files with PyKE.)

desertnaut
  • 57,590
  • 26
  • 140
  • 166
zabop
  • 6,750
  • 3
  • 39
  • 84

1 Answers1

1

You can apply a threshold and use open cv to analyze the number of connected components (groups). For example :

import cv2
src = cv2.imread('/path/to/your/image')
ret, thresh = cv2.threshold(src,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
connectivity = 8 #also diagonal neighbors, choose 4 if you want just horizontal and vertical neighbors. 
# Analysis of the binary image
output = cv2.connectedComponentsWithStats(thresh, connectivity, cv2.CV_32S)
n_groups=output[2].max()

To get rid of the noises you can decide that you don't take into account groups with less than TH number of connected pixels (from the images you uploaded as an example I would choose something like TH=4).

Binyamin Even
  • 3,318
  • 1
  • 18
  • 45