```python import numpy as np from skimage import io, color import matplotlib.pyplot as plt # 1. 生成一个600行,600列,为灰色([127,127,127]),中间300行,300列为蓝色的图。 image = np.ones((600, 600, 3), dtype=np.uint8) * 127 image[150:450, 150:450] = [0, 0, 255] # 2. 将生成的图灰色变为黄色,蓝色变为红色 image[image == [127, 127, 127]] = [255, 255, 0] image[image == [0, 0, 255]] = [255, 0, 0] # 3. 将改变后的图二值化,中间为白,周围为黑(彩转灰度图,公式自选) gray_image = color.rgb2gray(image) binary_image = (gray_image > 0.5).astype(np.uint8) * 255 # 显示图像 plt.imshow(binary_image, cmap='gray') plt.show() ``` [2024-10-17 10:33:15 | AI写代码神器 | 320点数解答]