这个用例说明Python 的图像基本运算
import numpy as np
from skimage import data
import matplotlib.pyplot as plt
camera = data.camera()
# 将图像前面10行的值赋为0
camera[:10] = 0
# 寻找图像中像素值小于87的像素点
mask = camera < 87
# 将找到的点赋值为255
camera[mask] = 255
# 建立索引
inds_x = np.arange(len(camera))
inds_y = (4 * inds_x) % len(camera)
# 对应索引的像素赋值为0
camera[inds_x, inds_y] = 0
# 获取图像的行数(高),列数(宽)
l_x, l_y = camera.shape[0], camera.shape[1]
# 建立网格坐标索引
X, Y = np.ogrid[:l_x, :l_y]
# 生成圆形的网格坐标
outer_disk_mask = (X - l_x / 2)**2 + (Y - l_y / 2)**2 > (l_x / 2)**2
# 对网格坐标赋0
camera[outer_disk_mask] = 0
# 建立figure的尺寸比例
plt.figure(figsize=(4, 4))
# 显示图像
plt.imshow(camera, cmap='gray', interpolation='nearest')
# 关掉图像的坐标
plt.axis('off')
plt.show()