我想知道如何閱讀(如果可能的話)增強后的影像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
uj5u.com熱心網友回復:
該變數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)
uj5u.com熱心網友回復:
您的四維陣列可能無法解釋為影像。
嘗試
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://www.uj5u.com/houduan/505110.html
標籤:Python 麻木的 python成像库 图像增强 唱片公司
下一篇:繪制非連續函式?
