-
-
Save stephengruppetta/6278f698879f1e55aaa0beeec74bb6c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
image = plt.imread("gardens.jpg") | |
# Create a figure | |
fig, axs = plt.subplot_mosaic( | |
[ | |
["colour", "colour", "colour"], | |
["colour", "colour", "colour"], | |
["colour", "colour", "colour"], | |
["red", "green", "blue"], | |
] | |
) | |
axs["colour"].imshow(image) | |
axs["colour"].axis("off") | |
# Create red channel image. I'll keep these images as 3D arrays | |
# and set the second and third layers, which represent the green | |
# and blue channels, to 0 | |
image_red = image.copy() | |
image_red[:, :, 1:] = 0 | |
# Same for the green image, but now the first and third layers | |
# are set to 0 | |
image_green = image.copy() | |
image_green[:, :, 0] = 0 | |
image_green[:, :, 2] = 0 | |
image_blue = image.copy() | |
image_blue[:, :, 0:2] = 0 | |
# Plot the separate channels | |
axs["red"].imshow(image_red) | |
axs["red"].axis("off") | |
axs["green"].imshow(image_green) | |
axs["green"].axis("off") | |
axs["blue"].imshow(image_blue) | |
axs["blue"].axis("off") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment