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()
相关推荐
万粉变现经纪人6 天前
如何解决pip安装报错ModuleNotFoundError: No module named ‘pillow’问题
python·pycharm·beautifulsoup·pandas·pillow·pip·策略模式
旷世奇才李先生21 天前
Pillow 安装使用教程
深度学习·microsoft·pillow
微信公众号:AI创造财富1 个月前
构建 docket uable to prepar context: path “.“ not found
python·plotly·flask·pillow·ipython·tornado
Code_流苏2 个月前
Python趣学篇:交互式词云生成器(jieba + Tkinter + WordCloud等)
python·pillow·matplotlib·tkinter·wordcloud·jieba分词·词云生成器
胡耀超2 个月前
图像颜色理论与数据挖掘应用的全景解析
人工智能·python·opencv·计算机视觉·数据挖掘·视觉检测·pillow
Sean X3 个月前
Pillow 移除或更改了 FreeTypeFont.getsize() 方法
pillow
guest_8813 个月前
用 Python 打造打篮球字符动画!控制台彩色炫酷输出,抖音搞怪视频灵感还原
开发语言·python·numpy·pillow
朴拙数科3 个月前
艺术字体AI生成阿里云WordArt锦书、通义万相、SiliconFlow、Pillow+OpenCV本地生成艺术字体
人工智能·阿里云·pillow
Earth explosion5 个月前
Python的pdf2image库将PDF文件转换为PNG图片
python·pdf·pillow
西农小陈6 个月前
Python-基于PyQt5,Pillow,pathilb,imageio,moviepy,sys的GIF(动图)制作工具(进阶版)
开发语言·图像处理·python·小程序·pycharm·pyqt·pillow