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()
相关推荐
SamChan9016 天前
图片翻译后文字挤出边框?用 Pillow 测量译文,不再靠字符数猜宽度
图像处理·python·pillow·本地化·图片翻译
许墨の小蝴蝶18 天前
Pillow 替换图片文字后字号偏小的排查
python·pillow
MoRanzhi120319 天前
第 9 篇 · 数值计算与图像处理:NumPy、SciPy、Pillow
图像处理·python·数值计算·numpy·pillow·信号处理·scipy
winfredzhang1 个月前
用 Python 手写一个“所见即所得“的图片水印工具:wxPython + Pillow 实战详解
python·pillow·rotate·crop·身份改水印
meiying88381 个月前
电商图片批量处理实战:Python+Pillow 一键完成裁剪、压缩、水印与格式转换
python·pillow
qq_161111272 个月前
Pillow项目深度解析:Python图像处理的终极武器
图像处理·python·pillow·开源库·历史解析
阿图灵2 个月前
OpenCV 实用技巧三连:视频转图片、图片转视频、Pillow 与 OpenCV 互转
图像处理·python·opencv·计算机视觉·音视频·pillow
Ming_studying2 个月前
Python批量压缩图片:支持JPG_PNG_WebP、尺寸限制与CSV报告
开发语言·图像处理·python·pillow·图片压缩
AndrewHZ2 个月前
图像处理入门012 | 图像裁剪与缩放:resize 与 ROI 操作
图像处理·opencv·pillow·插值·resize·letterbox·roi
AndrewHZ2 个月前
图像处理入门010 | Pillow 与 OpenCV 对比:双库图像读写实战
图像处理·opencv·计算机视觉·pillow