Nat*_*ate 8 python numpy image-processing scipy
我正在编写一个库来处理Python中的凝视跟踪,而且我对整个numpy/scipy世界都很陌生.基本上,我希望及时获取一系列(x,y)值,并将某些形状"绘制"到这些坐标的画布上.例如,形状可能是模糊的圆圈.
我想到的操作与在Photoshop中使用画笔工具或多或少完全相同.
我有一个交互式算法,可以将我的"画笔"修剪到我的图像范围内,并将每个点添加到累加器图像中,但它很慢(!),看起来似乎有一种从根本上更简单的方法来做到这一点.
关于从哪里开始寻找的任何指针?
在你的问题中,你描述了一个高斯滤波器,scipy通过一个包支持.例如:
from scipy import * # rand
from pylab import * # figure, imshow
from scipy.ndimage import gaussian_filter
# random "image"
I = rand(100, 100)
figure(1)
imshow(I)
# gaussian filter
J = gaussian_filter(I, sigma=10)
figure(2)
imshow(J)
Run Code Online (Sandbox Code Playgroud)
当然,您可以使用切片将其应用于整个图像,或仅应用于修补程序:
J = array(I) # copy image
J[30:70, 30:70] = gaussian_filter(I[30:70, 30:70], sigma=1) # apply filter to subregion
figure(2)
imshow(2)
Run Code Online (Sandbox Code Playgroud)
对于基本图像处理,Python图像库(PIL)可能就是您想要的.
注意:对于使用"画笔"进行"绘画",我认为您可以使用画笔创建一个布尔蒙版数组.例如:
# 7x7 boolean mask with the "brush" (example: a _crude_ circle)
mask = array([[0, 0, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 0, 0]], dtype=bool)
# random image
I = rand(100, 100)
# apply filter only on mask
# compute the gauss. filter only on the 7x7 subregion, not the whole image
I[40:47, 40:47][mask] = gaussian_filter(I[40:47, 40:47][mask], sigma=1)
Run Code Online (Sandbox Code Playgroud)