Astronomy Python - Coloring Grey Image using False Color

 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 intensity of the pixel
        if r < 128:
            pixels[i, j] = (64, 64, 64) # Red
        elif r < 192:
            pixels[i, j] = (204, 102, 0) # Green
        else:
            pixels[i, j] = (0, 0, 255) # Blue

# Save the modified image
rgb_img.save("E:\\astronomy_related\\falseimage_color\\false_colored_image.jpg")

*********************************************************************

Credits-

Code Credit-(Some modification is done in original code as per the need)
https://chat.openai.com

Image Credit: NASA/JPL-Caltech
Sol 3724: Left Navigation Camera
This image was taken by NAV_LEFT_B onboard NASA's Mars rover Curiosity on Sol 3724 (2023-01-27T13:16:41.000Z)

For getting "image color codes" use below web link
https://www.calculatorx.com/web/color/RGB_Color.htm



Comments

Popular posts from this blog

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

Python code to fetch Eta Carinae nebula FITS image and Display

Smart Telescopes - Interesting videos from Youtube.