PIL: Pillow Image.fromarray()

复制代码
## 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()
相关推荐
wei20237 天前
Windows安装OpenManus pillow版本错误
pillow
Cherry的跨界思维10 天前
5、Python长图拼接终极指南:Pillow/OpenCV/ImageMagick三方案
javascript·python·opencv·webpack·django·pillow·pygame
生而为虫19 天前
28.Python处理图像
人工智能·python·计算机视觉·pillow·pygame
AndrewHZ1 个月前
【图像处理基石】如何从动漫参考图中提取色彩风格?
图像处理·人工智能·opencv·pillow·聚类算法·色彩风格·色彩分布
小小测试开发1 个月前
Python数据科学与图像处理利器组合:Prophet、Arch、Scikit-image、Pillow-heif用法全解析
图像处理·python·pillow
萧鼎1 个月前
Python 图像处理利器:Pillow 深度详解与实战应用
图像处理·python·pillow
Kratzdisteln2 个月前
【Python】绘制椭圆眼睛跟随鼠标交互算法配图详解
python·数学·numpy·pillow·matplotlib·仿射变换
MoRanzhi12032 个月前
Pillow 基础图像操作与数据预处理
图像处理·python·深度学习·机器学习·numpy·pillow·数据预处理
Derrick__13 个月前
Python常用三方模块——Pillow
开发语言·python·pillow
eqwaak03 个月前
Pillow高级实战案例:图像处理的进阶应用
开发语言·python·科技·语言模型·pillow