📜  Python PIL | getbands() 和 getextrema() 方法

📅  最后修改于: 2022-05-13 01:55:28.916000             🧑  作者: Mango

Python PIL | getbands() 和 getextrema() 方法

Python PIL 库包含 Image 模块,其中定义了各种功能。 PIL.Image.Image.getbands()
此方法用于获取图像中存在的模式(波段)。

Python3
# Importing Image module from PIL package
from PIL import Image
 
# Opening a multiband image
im = Image.open(r"C:\Users\Admin\Pictures\images.png")
 
# This returns the bands used in im (image)
im1 = Image.Image.getbands(im)
 
print("Multiband image", im1)
 
# Opening a single band image
im2 = Image.open(r"C:\Users\Admin\Pictures\singleband.png")
 
# This returns the band used in im2
im3 = Image.Image.getbands(im2)
 
print("Single band image", im3)


Python3
# importing Image module from PIL package
from  PIL import Image
 
# opening a multiband image
im = Image.open(r"C:\Users\Admin\Pictures\download.png")
 
# getting maximum and minimum pixels of
# multiband images (RBG)
im1 = Image.Image.getextrema(im)
 
print("Multi band image ", im1)
 
# Opening a single band image
im2 = Image.open(r"C:\Users\Admin\Pictures\singleband.png")
 
# getting maximum and minimum pixels of
# single band image
im3 = Image.Image.getextrema(im2)
 
print("Single band image ", im3)


输出:

Multiband image ('R', 'G', 'B')
Single band image ('P', )

PIL.Image.Image.getextrema() 方法 –

获取图像中每个波段的最小和最大像素值。

Python3

# importing Image module from PIL package
from  PIL import Image
 
# opening a multiband image
im = Image.open(r"C:\Users\Admin\Pictures\download.png")
 
# getting maximum and minimum pixels of
# multiband images (RBG)
im1 = Image.Image.getextrema(im)
 
print("Multi band image ", im1)
 
# Opening a single band image
im2 = Image.open(r"C:\Users\Admin\Pictures\singleband.png")
 
# getting maximum and minimum pixels of
# single band image
im3 = Image.Image.getextrema(im2)
 
print("Single band image ", im3)

输出:

Multi band image  ((73, 255), (0, 255), (0, 255))
Single band image  (0, 123)

上述文章中使用的这些图像 -
多波段图像

单波段图像