我有一个简单的 2d numpy 数组,它是灰度图像的像素图。我正在尝试打印图像的某些部分。我的代码是
from google.colab import drive
drive.mount('/content/drive')
import numpy as np
import matplotlib.pyplot as plt
import cv2
img = cv2.imread('/content/drive/My Drive/Colab Notebooks/sample2.jpg') # the source file is correctly mounted
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
和
i = 0
while i < (len(roi) - 1): # roi is a list of strictly increasing positive integers
print(roi[i], roi[i+1])
plt.imshow(img_gray[roi[i]:roi[i+1]], cmap='gray')
i += 1
例如,如果roi = [10, 40, 50, 100],它应该打印图像的两个部分。但是当我运行上面的单元格时,它只打印一张图像,即图像的最后一部分。是否可以不覆盖其他图像并将其全部打印?
RISEBY
相关分类