我想知道如何阅读(如果可能的话)图像后,由Albumentations增强。
我试过:
my_img = 'xyz.jpg'
image = cv2.imread(my_img)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
transformed = transform(image=image)
new_img = np.array(list(transformed.values())
Image.formarray(new_img)但我知道这个错误:
TypeError: Cannot handle this data type: (1, 1, 512, 3), |u1发布于 2022-09-05 14:27:34
变量transformed是字典类型。您必须将存储在键image中的值显示为图像数组。
>>> type(transformed)
<class 'dict'>
# store the value in image key as an array & display it
transformed_image = transformed['image']
cv2.imshow(transformed_image)发布于 2022-09-05 13:41:40
您的四维数组很可能无法解释为图像。
试一试
new_img = np.squeeze(new_img)若要删除前两个维度,并在调用dtype=np.uint8时指定np.array。
然而,你的尺寸似乎仍然不匹配。如果您期望得到512 x 512图像,那么您的尺寸在压缩之前会看起来类似于(1,1,512,512,3),而在压缩之后(512,512,3)。
请考虑以下示例:
import numpy as np
import cv2 as cv
black_1d = np.zeros((1, 1, 512, 3), dtype=np.uint8)
# This doesn't work, it yields an error
# cv.imshow('Test', black)
# cv.waitKey()
# This works
new_img_1d = np.squeeze(black_1d)
cv.imshow('Test 1', new_img_1d)
cv.waitKey()
black_2d = np.zeros((1, 1, 512, 512, 3), dtype=np.uint8)
new_img_2d = np.squeeze(black_2d)
cv.imshow('Test 2', new_img_2d)
cv.waitKey()https://stackoverflow.com/questions/73609298
复制相似问题