有没有一种方法可以将作为二进制字符串加载的图像转换为numpy数组(im_height,im_width,3)?像这样:
# read image as binary string
with open(img_path, "rb") as image_file:
image_string = image_file.read()
# convert image string to numpy
image_np = convert_binary_string_to_numpy(image_string)
转换功能如何?我正在使用解密,因此我需要使用二进制字符串。 谢谢!
答案 0 :(得分:1)
import io
import numpy as np
from PIL import Image
image_string = open(IMG_PATH, 'rb').read()
img = Image.open(io.BytesIO(image_string))
arr = np.asarray(img)