我有一个float64类型的numpy数组a.如何使用高斯滤波器对这些数据进行模糊处理?
I have got a numpy array a of type float64. How can I blur this data with a Gauss filter?
我尝试过
from PIL import Image, ImageFilter image = Image.fromarray(a) filtered = image.filter(ImageFilter.GaussianBlur(radius=7)),但这会产生ValueError: 'image has wrong mode'. (它的模式为F.)
, but this yields ValueError: 'image has wrong mode'. (It has mode F.)
我可以通过将a与某个常数相乘,然后四舍五入为整数来创建合适模式的图像.那应该可以,但是我想有一个更直接的方法.
I could create an image of suitable mode by multiplying a with some constant, then rounding to integer. That should work, but I would like to have a more direct way.
(我使用的是Pillow 2.7.0.)
(I am using Pillow 2.7.0.)
推荐答案如果有二维numpy数组a,则可以直接在其上使用高斯滤波器,而无需先使用Pillow将其转换为图像. scipy具有功能 gaussian_filter 一样.
If you have a two-dimensional numpy array a, you can use a Gaussian filter on it directly without using Pillow to convert it to an image first. scipy has a function gaussian_filter that does the same.
from scipy.ndimage.filters import gaussian_filter blurred = gaussian_filter(a, sigma=7)更多推荐
如何对浮点数numpy数组进行高斯滤波(模糊)
发布评论