-
-
Save stephengruppetta/8b849a92dff3afadf85239c1dcf4f67c 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 | |
mosaic = """ | |
aaab | |
aaac | |
aaad | |
efg. | |
""" | |
fig, axs = plt.subplot_mosaic( | |
mosaic | |
) | |
axs["a"].imshow(image) | |
axs["a"].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["e"].imshow(image_red) | |
axs["e"].axis("off") | |
axs["f"].imshow(image_green) | |
axs["f"].axis("off") | |
axs["g"].imshow(image_blue) | |
axs["g"].axis("off") | |
# Plot the histograms | |
axs["b"].hist(image[:, :, 0].ravel(), bins=50, color="red") | |
axs["b"].axis("off") | |
axs["c"].hist(image[:, :, 1].ravel(), bins=50, color="green") | |
axs["c"].axis("off") | |
axs["d"].hist(image[:, :, 2].ravel(), bins=50, color="blue") | |
axs["d"].axis("off") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment