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()
相关推荐
西农小陈4 天前
Python-基于PyQt5,Pillow,pathilb,imageio,moviepy,sys的GIF(动图)制作工具(进阶版)
开发语言·图像处理·python·小程序·pycharm·pyqt·pillow
西农小陈5 天前
Python-基于PyQt5,Pillow,pathilb,imageio,moviepy,sys的GIF(动图)制作工具
python·小程序·pycharm·pyqt·pillow
西农小陈6 天前
Python-基于PyQt5,wordcloud,pillow,numpy,os,sys等的智能词云生成器
开发语言·python·小程序·pycharm·numpy·pyqt·pillow
西农小陈10 天前
Python-基于PyQt5,wordcloud,pillow,numpy,os,sys的智能词云生成器
开发语言·python·小程序·pycharm·numpy·pyqt·pillow
小青柑-1 个月前
完整的 Pillow 使用教程
图像处理·python·pillow
深蓝海拓1 个月前
基础的基础之 pillow与opencv相比的特点与优缺点比较
人工智能·opencv·pillow
码上好玩2 个月前
vscode写python,遇到问题:ModuleNotFoundError: No module named ‘pillow‘(已解决 避坑)
vscode·python·pillow
CN.LG2 个月前
浅谈Python库之pillow
开发语言·python·pillow
觅远2 个月前
python+img2pdf 快速图片转pdf+(img2pdf.ExifOrientationError处理、文件被打开或占用报错处理)
python·pdf·pillow