import matplotlib.pyplot as plt
import numpy as np

# Create a 4x4 grid of random colors for the main image
data = np.random.randint(0, 256, (4, 4, 3))

# Create the figures and subplots with updated text annotations
fig, axs = plt.subplots(1, 4, figsize=(12, 3))

# Display the full color image
axs[0].imshow(data)
axs[0].set_title('Full Color')
axs[0].axis('off')

# Display the individual channels with text annotations
colors = ['Red Channel', 'Green Channel', 'Blue Channel']
for i in range(3):
    # Isolate individual color channels, keeping the rest as black
    temp_data = np.zeros_like(data)
    temp_data[:, :, i] = data[:, :, i]
    axs[i+1].imshow(temp_data)
    axs[i+1].set_title(colors[i])
    axs[i+1].axis('off')
    # Annotate each cell in the channel with its value
    for (j, k), val in np.ndenumerate(temp_data[:, :, i]):
        axs[i+1].text(k, j, str(val), ha='center', va='center', color='white')

plt.tight_layout()
plt.show()
# Create a 4x4 grid of random grayscale values for 1-bit and 8-bit examples
# 1-bit (binary): Values can be either 0 or 255 (black or white)
data_1bit = np.random.choice([0, 255], (4, 4))

# 8-bit: Values range from 0 to 255 (grayscale)
data_8bit = np.random.randint(0, 256, (4, 4))

# Create the figures and subplots
fig, axs = plt.subplots(1, 2, figsize=(8, 4))

# Display the 1-bit grayscale image
axs[0].imshow(data_1bit, cmap='gray', vmin=0, vmax=255)
axs[0].set_title('1-bit Grayscale')
axs[0].axis('off')
# Annotate each cell with its value in 1-bit image
for (j, k), val in np.ndenumerate(data_1bit):
    axs[0].text(k, j, str(val), ha='center', va='center', color='white' if val < 128 else 'black')

# Display the 8-bit grayscale image
axs[1].imshow(data_8bit, cmap='gray', vmin=0, vmax=255)
axs[1].set_title('8-bit Grayscale')
axs[1].axis('off')
# Annotate each cell with its value in 8-bit image
for (j, k), val in np.ndenumerate(data_8bit):
    axs[1].text(k, j, str(val), ha='center', va='center', color='white' if val < 128 else 'black')

plt.tight_layout()
plt.show()