【发布时间】:2015-07-07 08:16:29
【问题描述】:
我有一个 float64 类型的 numpy 数组 a。如何使用高斯滤波器模糊这些数据?
我试过了
from PIL import Image, ImageFilter
image = Image.fromarray(a)
filtered = image.filter(ImageFilter.GaussianBlur(radius=7))
,但这会产生ValueError: 'image has wrong mode'。 (它有模式F。)
我可以通过将a 与某个常数相乘,然后舍入为整数来创建合适模式的图像。这应该可行,但我想有一个更直接的方法。
(我使用的是 Pillow 2.7.0。)
【问题讨论】:
-
你需要这个来使用枕头吗?如果你有你的二维数组
a,直接“模糊”数据而不先创建图像就足够了吗? -
你能通过转换
image = image.convert('L')和applyImageFilter.GaussianBlur这样的模式来测试吗? -
@Carsten - 如何“直接”模糊它?
-
@JohnGalt - 数组包含
0.03之类的数据。这不能直接转换为“L”,因为“L”表示“8 位灰度”。
标签: python numpy filtering python-imaging-library