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()
相关推荐
向日的葵0066 天前
阿里云OSS从0到1实战:为宠物收养系统打造图片上传功能
python·阿里云·云计算·pillow·fastapi·宠物
Dxy123931021612 天前
Python Pillow库:`img.format`与`img.mode`的区别详解
开发语言·python·pillow
yuanpan12 天前
Python + Pillow 实战:开发一个图片批量格式转换工具
python·microsoft·pillow
万粉变现经纪人1 个月前
如何解决 import aiohttp ModuleNotFoundError: No module named ‘aiohttp’
python·scrapy·beautifulsoup·aigc·pillow·pip·httpx
智算菩萨1 个月前
【Python图像处理】5 Pillow图像处理与格式转换
图像处理·python·pillow
nFBD29OFC2 个月前
pillow - 图像处理的瑞士军刀
图像处理·人工智能·pillow
万粉变现经纪人2 个月前
如何解决 pip install pillow-simd 报错 需要 AVX2/特定编译器 支持 问题
python·scrapy·beautifulsoup·aigc·pandas·pillow·pip
MoRanzhi12032 个月前
Pillow 图像分割、切片与拼接处理
图像处理·人工智能·python·计算机视觉·pillow·图像拼接·网格分块
MoRanzhi12032 个月前
pillow 图像合成、透明叠加与蒙版处理
python·计算机视觉·pillow·图片处理·图像合成·透明叠加·多图层叠加
MoRanzhi12032 个月前
Pillow 图像算术运算与通道计算
图像处理·人工智能·python·计算机视觉·pillow·图像差异检测·图像算术运算