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-
*************************************************
import cv2import numpy as np# Load the imageimage = cv2.imread('E:\\astronomy_related\\wint_sky_j.jpg')# Convert the image to grayscalegray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)# Blur the image to reduce noiseblurred = 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 imagecontours = 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 onefor 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 imagecv2.imshow('Bright Spots', image)cv2.waitKey(0)# Print the number of bright spotsprint('Number of bright spots:', len(contours))
Comments
Post a Comment