```python import numpy as np from skimage import io from skimage.color import rgb2gray import matplotlib.pyplot as plt # Generate image with grey background and blue square in the middle image = np.full((600, 600, 3), [127, 127, 127], dtype=np.uint8) image[150:450, 150:450] = [0, 0, 255] # Change colors to yellow and red yellow_mask = (image[..., 0] == 127) & (image[..., 1] == 127) & (image[..., 2] == 127) image[yellow_mask] = [255, 255, 0] red_mask = (image[..., 0] == 0) & (image[..., 1] == 0) & (image[..., 2] == 255) image[red_mask] = [255, 0, 0] # Convert image to grayscale gray_image = rgb2gray(image) # Binarize image threshold = 0.5 binary_image = np.where(gray_image >= threshold, 255, 0).astype(np.uint8) # Display the images fig, axs = plt.subplots(1, 3, figsize=(15, 5)) axs[0].imshow(image) axs[0].set_title('Original Image') axs[1].imshow(gray_image, cmap='gray') axs[1].set_title('Gray Image') axs[2].imshow(binary_image, cmap='binary') axs[2].set_title('Binary Image') plt.show() ``` [2024-10-17 10:32:40 | AI写代码神器 | 685点数解答]