iPython imshow() 或 numpy 行选择

iPython imshow() or numpy row selection

我正在尝试使用 imshow() 绘制我拥有的图像的中间一百行。我想知道是否有任何 numpy 命令只能对图像数组的中间一百行进行切片。如果没有,我可以使用 imshow() 本身的一些变体来 select 并仅显示中间的一百行吗?

您要找的是:

pic[np.shape(pic)[0]/2-50:np.shape(pic)[0]/2+50,np.shape(pic)[1]/2-50:np.shape(pic)[1]/2+50]

示例代码:

import numpy as np
import matplotlib.pyplot as plt

pic = np.random.rand(300,300)
fig1 = plt.figure()
fig1.suptitle('Full image')
plt.imshow(pic)
cropped = pic[np.shape(pic)[0]/2-50:np.shape(pic)[0]/2+50,np.shape(pic)[1]/2-50:np.shape(pic)[1]/2+50]
fig2 = plt.figure()
fig2.suptitle('middle 100 rows and column cropped')
plt.imshow(cropped)
plt.show()

结果: