Astronomy Python - Chatgpt based- Count Star from the Image

Every person who is interested in analyzing night sky image should try the python script mentioned in the blog. 

Special Thanks and all credit goes to "Chatgpt", who has generated the code (with minor modifications from my side). Below is  image of night sky-

Execute below program in juypter notebook

*************************************************
import cv2
import numpy as np

# Load the image
image = cv2.imread('E:\\astronomy_related\\wint_sky_j.jpg')

# Convert the image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Blur the image to reduce noise
blurred = cv2.GaussianBlur(gray, (5, 5), 0)

# Threshold the image to create a binary image
#thresh = cv2.threshold(blurred, 220, 255, cv2.THRESH_BINARY)[1]
thresh = cv2.threshold(blurred, 150, 255, cv2.THRESH_BINARY)[1]

# Find contours in the image
contours = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours = contours[0] if len(contours) == 2 else contours[1]

# Loop through the contours and draw a rectangle around each one
for c in contours:
    x,y,w,h = cv2.boundingRect(c)
    #cv2.rectangle(image, (x, y), (x + w, y + h), (36,255,12), 2)
    cv2.circle(image, (x,y), 10, (0, 250, 255), 1)

# Show the image
cv2.imshow('Bright Spots', image)
cv2.waitKey(0)

# Print the number of bright spots
print('Number of bright spots:', len(contours))
*********************************************************
Below output is created.

You may change
1)Threshold to count more dimmer star
2)instead of putting yellow circle, rectangle dot can be drawn





Comments

Popular posts from this blog

Astronomy Python - Webb's First Deep Field - Marking the Edges of the Galaxies

Online Observatory for Meteor Scatter Detection - Radio Astronomy.

Astronomy Python - Mars Planet Surface - Creating Sharpen Image from Blur Image