## DEPTH
import numpy as np
from PIL import Image
# Create a 2D NumPy array
gray_array = np.random.randint(0, 255, (224, 224), dtype=np.uint8)
img = Image.fromarray(gray_array)
img.show()
## RGB
rgb_array = np.random.randint(0, 255, (224, 224, 3), dtype=np.uint8)
img = Image.fromarray(rgb_array)
img.show()
## SET THE MODE
rgba_array = np.random.randint(0, 255, (224, 224, 4), dtype=np.uint8)
img = Image.fromarray(rgba_array, mode='RGBA')
img.show()
#如果你的数组是 (224, 224, 4) (具有 4 个通道的深度图像),并且您想在 RGB 中使用它
import numpy as np
from PIL import Image
# Example depth array
depth_array = np.random.randint(0, 255, (224, 224, 4), dtype=np.uint8)
# Drop the alpha channel (use only the first three channels)
depth_rgb = depth_array[:, :, :3]
# Convert to PIL Image
img = Image.fromarray(depth_rgb)
img.show()
##如果你的数组是 (224, 224, 3):
img = Image.fromarray(arr)
img.show()