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()
相关推荐
qq_161111276 天前
Pillow项目深度解析:Python图像处理的终极武器
图像处理·python·pillow·开源库·历史解析
阿图灵6 天前
OpenCV 实用技巧三连:视频转图片、图片转视频、Pillow 与 OpenCV 互转
图像处理·python·opencv·计算机视觉·音视频·pillow
Ming_studying9 天前
Python批量压缩图片:支持JPG_PNG_WebP、尺寸限制与CSV报告
开发语言·图像处理·python·pillow·图片压缩
AndrewHZ11 天前
图像处理入门012 | 图像裁剪与缩放:resize 与 ROI 操作
图像处理·opencv·pillow·插值·resize·letterbox·roi
AndrewHZ13 天前
图像处理入门010 | Pillow 与 OpenCV 对比:双库图像读写实战
图像处理·opencv·计算机视觉·pillow
谙忆2 个月前
Python 常用图像处理库速查:Pillow、OpenCV、rembg、pillow-simd 各擅长什么、怎么选
图像处理·python·pillow
2601_961875243 个月前
花生十三资料1200题|题库|刷题
conda·pytest·pillow·pip·web3.py·ipython·gunicorn
恣艺3 个月前
Python 图像处理实战:Pillow 与 OpenCV 从入门到精通
图像处理·python·pillow
向日的葵0064 个月前
阿里云OSS从0到1实战:为宠物收养系统打造图片上传功能
python·阿里云·云计算·pillow·fastapi·宠物
Dxy12393102164 个月前
Python Pillow库:`img.format`与`img.mode`的区别详解
开发语言·python·pillow