【发布时间】:2021-05-10 17:23:35
【问题描述】:
我正在尝试从驱动器上的目录中读取图像,为此我使用 OpenCV,我将图像转换为 32 位浮点数的 numpy 数组,然后显示它,我遇到的问题是图像不显示。这些图像对应于胸部 X 光片,我在 Google Colab 工作。
import matplotlib.pyplot as plt
import cv2
from skimage import transform
import numpy as np
img_r = cv2.imread('/content/drive/MyDrive/images/T-NORMAL- (3).jpeg')
img1 = np.array(img_r).astype('float32')/255
img2 = transform.resize(img1, (150, 150, 3))
plt.imshow(img2)
以为是我没有正确访问目录,所以使用了os.listdir方法,如下代码所示,反正图片没有显示出来。
import matplotlib.pyplot as plt
import os
import numpy as np
import cv2
from skimage import transform
items = os.listdir('/content/drive/MyDrive/imagenes')
print (items)
for each_image in items:
if each_image.endswith(".jpeg"):
print (each_image)
full_path = "/content/drive/MyDrive/imagenes" + each_image
print (full_path)
image = cv2.imread(full_path)
img1 = np.array(image).astype('float32')/255
img2 = transform.resize(img1, (150, 150, 3))
plt.imshow(img2)
This is what is displayed as a result of the second code.
我希望有人可以帮助我。 提前致谢。
【问题讨论】:
标签: python opencv google-colaboratory image-preprocessing