Skip to content

Instantly share code, notes, and snippets.

@hackerdem
Created May 4, 2016 19:53
Show Gist options
  • Save hackerdem/cf5ff212ef1a0bced869b661244a11c5 to your computer and use it in GitHub Desktop.
Save hackerdem/cf5ff212ef1a0bced869b661244a11c5 to your computer and use it in GitHub Desktop.
Count stars on a photo using python
import numpy as np
import pylab
import mahotas as mh
from skimage import measure
sky=mh.imread('sky.jpeg')
pylab.imshow(sky)
t=mh.thresholding.otsu(sky.astype('uint8'))
labeled,stars=mh.label(sky>t)
print stars
pylab.imshow(labeled)
pylab.jet()
pylab.show()
@SaraJ52
Copy link

SaraJ52 commented Feb 26, 2021

would you mind explaining it a bit ?

@hackerdem
Copy link
Author

google an image of sky at night, using libraries in this script, you can count the number of starts in the image.

@SaraJ52
Copy link

SaraJ52 commented Feb 27, 2021

hey! I got that. I even tried and it works fine. Was asking about the code tho. Could you explain the lines of code?

@hackerdem
Copy link
Author

It has been a long time, I don't remember line by line, but what it does this; it reads the image in terms of colour density,then based on a threshold you would define, it will count the areas which are brighter than the rest of image, so every dot in your image depending on the threshold in terms of size will be counted.

@SaraJ52
Copy link

SaraJ52 commented Feb 27, 2021

Thanks, mate! stay blessed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment