Posts

Showing posts from February, 2023

Astronomy Python - Crab Nebula - Combine RGB channel images into One Image

Image
 In Astronomy, Image taken by cameras would be based on specific filters(channels)-Red, Green, Blue. Below are the the images taken across 3 channels. Red(Left), Green(Centre), Blue(Right) Original image credit(single image which is not shown here)- Credits: NASA, ESA, J. Hester and A. Loll (Arizona State University) Below is result after combining above 3 channel images Below is the python code used. Original Carb Nebula image is spitted    into 3 channels(as shown 3 gray images above) *************************************************** from PIL import Image # Open the red, green, and blue channel images red_channel = Image.open('E:\\astronomy_related\\rbg_one\\red.png') green_channel=Image.open('E:\\astronomy_related\\rbg_one\\green.png') blue_channel =Image.open('E:\\astronomy_related\\rbg_one\\blue.png') # Create a new RGB image result = Image.merge("RGB", (red_channel, green_channel, blue_channel)) # Save the result image result.save('E:\\astr...

Astronomy Python - Hubble Ultra Deep Field - Invert Colors

Image
 In Astronomy, while studying Deep Field images, it would be necessary to invert the color of the image, to find out the object with a lesser magnitude. Deep Field images contains 10,000 of galaxies or stars with varying magnitudes. Below is the original image(left) and color inverted image(right). Image credit-NASA, ESA, and S. Beckwith (STScI) and the HUDF Team Below is the short  python code used. ********************************************************************** import cv2 image = cv2.imread("E:\\astronomy_related\\invert_image_colors\\HUD.jpg", 0) inverted_image = cv2.bitwise_not(image) cv2.imwrite("E:\\astronomy_related\\invert_image_colors\\HUD_inverted.jpg", inverted_image ) ********************************************************************** Credits- Image Credit- NASA, ESA, and S. Beckwith (STScI) and the HUDF Team https://esahubble.org/images/heic0406a/ code credit- https://www.delftstack.com/howto/python/opencv-invert-image/

Astronomy Python - Jupiter Planet - Cropping Red Gaint Spot

Image
 In Astronomy, there will be often need to crop(cut) certain part of image.  By using cropping technique, it becomes easy to highlight import part of the image, as shown in the below example,  Red Giant Spot is cropped and then shown in another window (top right). Image credit -Nasa Jupiter Below is the python code used. When code is executed original image appears and then selected the part of the image which you want to cut. ****************************************************************** import cv2 import numpy as np    # Read image image = cv2.imread("E:\\astronomy_related\\image_crop\\jupiter.jpg")    # Select ROI r = cv2.selectROI("select the area", image)    # Crop image cropped_image = image[int(r[1]):int(r[1]+r[3]),                        int(r[0]):int(r[0]+r[2])]    # Display cropped image cv2.imshow("Cropped image", cropped_image) cv2.waitKey(0) *********...

Astronomy Python - Webb's First Deep Field - Putting Grid Lines

Image
 In Astronomy, putting a grid line (with number blocks) on Image (planets, star field etc.) will simplify the image understanding process.  Each block could be treated as smaller part of the big image and block number could be used as reference number to locate an object. In the below example, a grid with number block(green in color) is applied to  Webb's First Deep Field image. Image Credits: NASA, ESA, CSA, STScI(without gird) Below is the python code used. ********************************************************************** import matplotlib.pyplot as plt import matplotlib.ticker as plticker try:     from PIL import Image except ImportError:     import Image # Open image file image = Image.open('E:\\astronomy_related\\xy_grid\\webb_first_deep_field_n.png') # Set up figure gridLineWidth=100 fig=plt.figure(figsize=(float(image.size[0])/gridLineWidth, float(image.size[1])/gridLineWidth), dpi=gridLineWidth) axes=fig.add_subplot(111) # Remove whitespac...

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

Image
  In Astronomy, the image taken by telescopes of deep space field, galaxies, planets may appear to be complex - it may be difficult to find boundaries of objects when objects are too near. Or  simply one would like to know the shape of the object. Edge detection technique is used in image processing for finding the boundaries of objects within the image. Edge detection would be very useful while analyzing such difficult images. Below is the sample image taken by James Webb telescope. Image Credits: NASA, ESA, CSA, STScI Below is grey image(left) and edge detection image(right) An edge detection operato r used in the above example is called as Canny edge detector Below is the python code used. ********************************************************************** import cv2 import numpy as np import matplotlib.pyplot as plt # read the image image = cv2.imread("E:\\astronomy_related\\edge_detection\\webb_first_deep_field.jpeg") # convert it to grayscale gray...

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

Image
   In Astronomy, sometimes the images send by satellite/telescope could be Blur and one would be interested to make the image Sharpe. The Kernel (it is matrix representation) is to process the image -from Blur image to Sharpe Image. Convolution Matrix, Mask, Matrix/Array are the other names given to the Kernel.                           Below is the example of Mars Surface Blur Image Image Credit: NASA/JPL-Caltech Below is the processed image which has now become  Sharpe Image   Please  open both images to see the effect.7 Below is the python code used. ****************************************************************** # load the required packages import cv2 import numpy as np # load the image into system memory image = cv2.imread('E:\\astronomy_related\\blurr_to_clear_image\\marssurface_blurr.jpg', flags=cv2.IMREAD_COLOR) # display the blurr image to the screen cv2.imshow('Mars Surface blurr...