给定值数组,如下所示:完整数组这里
[{"format": "rle", "rle": [0, 18, 192, 0, 57, 27, 255, 255, 255, 0, 259, 96, 17, 192, 97, 255, 248, 239, 227, 16, 2....., 255, 142, 3, 130, 21, 128, 0], "brushlabels": ["crack"], "original_width": 640, "original_height": 480}]如何转换以获得image.png?
发布于 2022-11-07 00:19:31
您可以使用np.reshape()方法将数组重塑为图像的原始维度:
import cv2
import numpy as np
data = [{"format": "rle", "rle": [255, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 255, 0, 0, 0, 255, 0, 0], "brushlabels": ["crack"], "original_width": 2, "original_height": 3}]
# Create image from data
img = np.uint8(data[0]["rle"]).reshape(data[0]["original_height"], data[0]["original_width"], 3)
# The image is completed, but it's tiny small in this example, so resize it to be able to visualize it
img = cv2.resize(img, (200, 300), interpolation=cv2.INTER_NEAREST)
# Show result
cv2.imshow("Result", img)
cv2.waitKey(0)输出:

https://stackoverflow.com/questions/74339154
复制相似问题