Posts

Showing posts from January, 2023

Astronomy Python - Creating Histogram of the Asteroid

Image
 Histogram of Image help us to understand distribution of color values in the image. In the below images, left image is of asteroid Bennu and right image is of Histogram. Below is the Python code used to create Histogram. **************************************************************************** from PIL import Image import numpy as np import matplotlib.pyplot as plt # Open the image file img = Image.open("E:\\astronomy_related\\image_to_histogram\\asteroid_bennu.jpg") # Convert the image to grayscale img = img.convert("L") # Convert the image data to a numpy array data = np.array(img) # Plot the histogram plt.hist(data.ravel(), bins=256, range=(0, 256), fc='k', ec='k') plt.show() ***************************************************************************** Credits and Information- Code Credit-(Some modification is done in original code as per the need) https://chat.openai.com Image Cedit and Information https://www.nasa.gov/image-feature/osiris-re

Astronomy Python - Coloring Grey Image using False Color

Image
 In Astronomy, the images send by satellite/telescope are often "Grey Color(scale) images". False coloring Technique is used to highlight the features in the grey colored images. Below is the example of Mars Surface & Rover in grey Colored(left image) and False colored(right image) Image Credit: NASA/JPL-Caltech Below is the python code used. Instead of using RBG(Reb, Blue and Green), Orange ,Blue & Black colors are used. ****************************************************************** from PIL import Image # Open the image img = Image.open("E:\\astronomy_related\\falseimage_color\\mars_surface_rover.jpg") # Convert the image to a 3-channel RGB image rgb_img = img.convert("RGB") # Get the pixel data as a 2D array pixels = rgb_img.load() # Loop through each pixel and change its color based on its intensity for i in range(img.width):     for j in range(img.height):         r, g, b = pixels[i, j]                  # Set the color based on the intensi

Astronomy Python - Chatgpt based- Stich Images Horizontally

Image
 Often  there will be need to put images one beside another for analyzing .  For example we have 3 images (shown below)and we want to align it in one single image one beside another. Below is the python script,   Special Thanks and all credit goes to "Chatgpt", who has generated the code, which will align the images one beside another. Below is the output. Individual Images are taken from below website https://asd.gsfc.nasa.gov/archive/mwmw/mmw_sci.html Python code below ******************************************************************* from PIL import Image # Open the images image1 = Image.open("E:\\astronomy_related\\imageoverlay\\image1.jpg") image2 = Image.open("E:\\astronomy_related\\imageoverlay\\image2.jpg") image3 = Image.open("E:\\astronomy_related\\imageoverlay\\image3.jpg") # Create a list of images images = [image1, image2, image3] # Determine the width and height of the final image widths, heights = zip(*(i.size for i in images)) to

Astronomy Python - Chatgpt based- Stich Images Vertically

Image
 Often there will be need to put images one below another for analyzing .  For example we have 3 images (shown below)and we want to align it in one single image one below another. Below is the python script,   Special Thanks and all credit goes to "Chatgpt", who has generated the code, which will align the image one below another. Below is the output. Individual Images are taken from below website https://asd.gsfc.nasa.gov/archive/mwmw/mmw_sci.html Python code below ******************************************************************* from PIL import Image # Open the images image1 = Image.open("E:\\astronomy_related\\imageoverlay\\image1.jpg") image2 = Image.open("E:\\astronomy_related\\imageoverlay\\image2.jpg") image3 = Image.open("E:\\astronomy_related\\imageoverlay\\image3.jpg") # Create a list of images images = [image1, image2, image3] # Determine the width and height of the final image widths, heights = zip(*(i.size for i in images)) max_wid

Astronomy Python - Chatgpt based- Count Star from the Image

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