如何对浮点数numpy数组进行高斯滤波(模糊)

编程入门 行业动态 更新时间:2024-10-11 21:30:02
本文介绍了如何对浮点数numpy数组进行高斯滤波(模糊)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个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数组进行高斯滤波(模糊)

本文发布于:2023-10-18 04:20:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1503083.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   高斯   模糊   浮点数   numpy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!