找到关于 Pillow 的 17 篇文章

使用 Pillow 库对图像应用 MinFilter

Prasad Naik
更新于 2021年3月18日 06:55:06

208 次浏览

在本程序中,我们将使用 Pillow 库对图像应用最小值滤波器。在最小值滤波中,图像中选定窗口中每个像素的值将被替换为该窗口的最小像素值。filter 函数用于使用 Pillow 库应用不同的滤波器。原始图像算法步骤 1:从 Pillow 中导入 Image。步骤 2:打开图像。步骤 3:调用 filter 函数并指定 minfilter。步骤 4:显示输出。示例代码from PIL import Image, ImageFilter im = Image.open('testimage.jpg') im1 = im.filter(ImageFilter.MinFilter(size = 7)) im1.show()输出

使用 Pillow 库旋转图像

Prasad Naik
更新于 2021年3月17日 08:45:51

750 次浏览

在本程序中,我们将使用 Pillow 库旋转图像。Image 类中的 rotate() 函数接收旋转角度。原始图像算法步骤 1:从 Pillow 中导入 Image 类。步骤 2:打开图像。步骤 3:旋转图像。步骤 4:显示输出。示例代码from PIL import Image im = Image.open('testimage.jpg') im.rotate(45).show()输出

使用 Pillow 库裁剪图像

Prasad Naik
更新于 2021年3月17日 08:46:10

233 次浏览

在本程序中,我们将使用 Pillow 库裁剪图像。我们将使用 crop() 函数来实现。该函数接收左、上、右、下像素坐标来裁剪图像。原始图像算法步骤 1:从 Pillow 中导入 Image。步骤 2:读取图像。步骤 3:使用 crop 函数裁剪图像。步骤 4:显示输出。示例代码from PIL import Image im = Image.open('testimage.jpg') width, height = im.size left = 5 top = height / 2 right = 164 bottom = 3 * height / 2 im1 = im.crop((left, top, right, bottom)) im1.show()输出

使用 Pillow 库加载和显示图像

Prasad Naik
更新于 2021年3月17日 08:46:35

162 次浏览

在本程序中,我们将使用 Pillow 库读取或加载图像。Pillow 库包含一个名为 Image.open() 的方法。此函数将文件路径或文件名作为字符串。要显示图像,我们使用另一个函数 show()。它不需要任何参数。示例代码from PIL import Image im = Image.open('testimage.jpg') im.show()输出

使用 Pillow 查找图像中的边缘

Prasad Naik
更新于 2021年3月17日 08:37:53

1K+ 次浏览

在本程序中,我们将使用 Pillow 库查找图像中的边缘。ImageFilter 类中的 FIND_EDGES 函数帮助我们找到图像中的边缘。原始图像算法步骤 1:从 Pillow 中导入 Image 和 ImageFilter。步骤 2:打开图像。步骤 3:调用 filter 函数并指定 find_edges 函数。步骤 4:显示输出。示例代码from PIL import Image, ImageFilter im = Image.open('testimage.jpg') im = im.filter(ImageFilter.FIND_EDGES) im.show()输出

使用 Pillow 库计算图像中每个波段所有像素的平均值

Prasad Naik
更新于 2021年3月17日 08:27:40

2K+ 次浏览

在本程序中,我们将使用 Pillow 库计算每个通道中所有像素的平均值。图像中共有三个通道,因此我们将得到一个包含三个值的列表。原始图像算法步骤 1:导入 Image 和 ImageStat 库。步骤 2:打开图像。步骤 3:将图像传递给 imagestat 类的 stat 函数。步骤 4:打印像素的平均值。示例代码from PIL import Image, ImageStat im = Image.open('image_test.jpg') stat = ImageStat.Stat(im) print(stat.mean)输出[76.00257724463832, 69.6674300254453, 64.38017448200654]

使用 Pillow 库计算图像中每个波段所有像素的中位数

Prasad Naik
更新于 2021年3月17日 08:16:31

770 次浏览

在本程序中,我们将使用 Pillow 库计算每个通道中所有像素的中位数。图像中共有 3 个通道,因此我们将得到一个包含三个值的列表。原始图像算法步骤 1:导入 Image 和 ImageStat 库。步骤 2:打开图像。步骤 3:将图像传递给 imagestat 类的 stat 函数。步骤 4:打印像素的中位数。示例代码from PIL import Image, ImageStat im = Image.open('image_test.jpg') stat = ImageStat.Stat(im) print(stat.median)输出[41, 43, 40]

广告

© . All rights reserved.