Red Scale Imaging

The following code uses pathlib to grab the image from the desired path. It uses PIL and io to read the file, then uses numpy

import IPython.display as display
from pathlib import Path
from PIL import Image
import io
import base64
import numpy as np

# Load the image
img_path = Path("images/download.jpg")  # Replace with the path to your image
with img_path.open("rb") as f:
    img = Image.open(io.BytesIO(f.read()))

# Convert the image to a numpy array
img_arr = np.array(img)

# Convert the image to red scale
red_scale = img_arr.copy()
red_scale[:, :, 1] = 0  # Set the green channel to 0
red_scale[:, :, 2] = 0  # Set the blue channel to 0

# Convert the red scale image back to a PIL image
red_scale_img = Image.fromarray(red_scale)

# Display the red scale image in the console
buffer = io.BytesIO()
red_scale_img.save(buffer, format="PNG")
display.display(display.Image(data=buffer.getvalue()))