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()
相关推荐
Derrick__113 天前
Python常用三方模块——Pillow
开发语言·python·pillow
eqwaak018 天前
Pillow高级实战案例:图像处理的进阶应用
开发语言·python·科技·语言模型·pillow
爱蹦跶的精灵18 天前
降级版本Pillow解决freetypefont has no attribute getsize问题
python·pillow
eqwaak019 天前
Python Pillow库详解:图像处理的瑞士军刀
开发语言·图像处理·python·语言模型·pillow
是乐谷1 个月前
Python图片转WebP常用库推荐:Pillow、Wand、cv2
大数据·运维·开发语言·人工智能·python·开源·pillow
WSSWWWSSW2 个月前
Python Imaging Library (PIL) 全面指南:PIL高级图像处理-分割与颜色空间转换
图像处理·python·计算机视觉·pillow
WSSWWWSSW2 个月前
Jupyter Notebook 中高效处理和实时展示来自 OpenCV 和 Pillow 的图像数据探究
opencv·jupyter·pillow
万粉变现经纪人3 个月前
如何解决pip安装报错ModuleNotFoundError: No module named ‘pillow’问题
python·pycharm·beautifulsoup·pandas·pillow·pip·策略模式
旷世奇才李先生3 个月前
Pillow 安装使用教程
深度学习·microsoft·pillow
微信公众号:AI创造财富4 个月前
构建 docket uable to prepar context: path “.“ not found
python·plotly·flask·pillow·ipython·tornado