将作为二进制字符串加载的图像转换为 numpy 数组

Convert image loaded as binary string into numpy array

有没有一种方法可以将作为二进制字符串加载的图像转换为大小为 (im_height、im_width、3) 的 numpy 数组?像这样:

# 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)

那个转换函数会是什么样子?我正在处理解密,因此我需要处理二进制字符串。 谢谢!

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)