“绘画”使用 python / numpy 将一个数组复制到另一个数组
我正在编写一个库来用 Python 处理注视跟踪,并且我对整个 numpy / scipy 世界相当陌生。本质上,我希望及时获取一组 (x,y) 值,并在这些坐标的画布上“绘制”一些形状。例如,形状可能是一个模糊的圆圈。
我想到的操作与使用 Photoshop 中的画笔工具大致相同。
我有一个交互式算法,可以将我的“画笔”修剪到图像的范围内,并将每个点添加到累加器图像中,但它很慢(!),而且似乎可能有一种根本上更简单的方法来做到这一点。
关于从哪里开始寻找的任何指示?
I'm writing a library to process gaze tracking in Python, and I'm rather new to the whole numpy / scipy world. Essentially, I'm looking to take an array of (x,y) values in time and "paint" some shape onto a canvas at those coordinates. For example, the shape might be a blurred circle.
The operation I have in mind is more or less identical to using the paintbrush tool in Photoshop.
I've got an interative algorithm that trims my "paintbrush" to be within the bounds of my image and adds each point to an accumulator image, but it's slow(!), and it seems like there's probably a fundamentally easier way to do this.
Any pointers as to where to start looking?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在您的问题中,您描述了一个高斯滤波器,scipy 通过 包 支持该滤波器。
例如:
当然,您可以使用切片将其应用于整个图像,或仅应用于补丁:
对于基本图像操作,Python 图像库 (PIL) 可能就是您想要的。
笔记:
对于用“画笔”“绘画”,我认为您可以用画笔创建一个布尔蒙版数组。例如:
In your question you describe a Gaussian filter, for which scipy has support via a package.
For example:
Of course, you can apply this on the whole image, or just on a patch, using slicing:
For basic image manipulation, the Python Image library (PIL) is probably what you want.
NOTE:
for "painting" with a "brush", I think you could just create a boolean mask array with your brush. For instance:
你真的应该研究一下 Andrew Straw 的 motmot 和 libcamiface。他将它用于苍蝇行为实验,但它是一个灵活的库,可以完成我认为您正在做的图像采集和处理。有一个关于他在 SciPy2009 上演讲的视频。
至于您提到的画笔场景,我将使用 .copy() 方法复制图像,将画笔图像保留在数组中,然后将其添加到
您设置的位置
first_br_row
,last_br_row
first_br_col
、last_br_col
定位要添加画笔的子图像以及first_row
、last_row
、first_col
、last_col
来剪辑画笔(通常将它们设置为 0 和 # rows/cols - 1,但当您足够接近画笔时进行调整)图像边界只想绘制画笔的一部分)。希望一切有帮助。
You should really look into Andrew Straw's motmot and libcamiface. He uses it for fly behaviour experiments but it's a flexible library for doing just the kind of image acquisition and processing you're doing I think. There's a video of his presentation at SciPy2009.
As for the paintbrush scenario you mention, I'd make a copy of the image with the .copy() method, keep the paintbrush image in an array, and simply add it with
where you set
first_br_row
,last_br_row
first_br_col
,last_br_col
to address the subimage where you want to add the brush andfirst_row
,last_row
,first_col
,last_col
to clip the brush (normally set them to 0 and # rows/cols - 1, but adjust when you're near enough to the image boundary to only want to paint part of the brush).Hope all that helps.
在傅里叶空间中做一些数学可能会有所帮助:平移(狄拉克卷积)等于傅里叶中的相位的简单乘法......这使您的画笔移动到确切的位置(与 catchmeifyoutry 和 catchmeifyoutry 类似的解决方案)。 dwf,但这允许比像素更精细的平移,例如 2.5,可惜有一些振铃)。那么,这样的笔划之和就是这些操作的总和。
在代码中:
Doing a little of math in Fourier space may help: a translation (convolution by a dirac) is equal to a simple multiplication by a phase in Fourier... this makes your paintbrush move to the exact place (a similar solution than catchmeifyoutry & dwf, but this allows a translation finer than the pixel, like 2.5, alas with some ringing). Then, a sum of such strokes is the sum of these operations.
In code:
OpenCV 使用 numpy 数组并具有基本的绘图功能:圆、椭圆、折线...
要绘制一条线,您可以
在每次收到鼠标事件时调用。
OpenCV uses numpy arrays and has basic drawing functions: circles, elipses, polylines...
To draw a line you can call
each time you get a mouse event.
您是否研究过Tkinter?
Python 图像库 也可能有一些帮助。
Have you looked into Tkinter?
Python Image Library may be some help too.