我正在尝试将二维高斯拟合到图像中。噪声非常低,所以我的尝试是旋转图像,使两个主轴不共变,找出最大值并计算两个维度的标准偏差。选择的武器是蟒蛇。
但是我在寻找图像的特征向量时遇到了困难 - numpy.linalg .py
假设离散数据点。我考虑过将此图像视为概率分布,对几千个点进行采样,然后根据该分布计算特征向量,但我确信一定有一种方法可以找到特征向量(即半主向量和半主向量)高斯椭圆的短轴)直接来自该图像。有什么想法吗?
多谢 :)
I'm trying to fit a 2D Gaussian to an image. Noise is very low, so my attempt was to rotate the image such that the two principal axes do not co-vary, figure out the maximum and just compute the standard deviation in both dimensions. Weapon of choice is python.
However I got stuck at finding the eigenvectors of the image - numpy.linalg.py
assumes discrete data points. I thought about taking this image to be a probability distribution, sampling a few thousand points and then computing the eigenvectors from that distribution, but I'm sure there must be a way of finding the eigenvectors (ie., semi-major and semi-minor axes of the gaussian ellipse) directly from that image. Any ideas?
Thanks a lot :)
发布评论
评论(3)
简单说明一下,有几种工具可以使图像适合高斯。我唯一能想到的是 scikits.learn,它不是完全以图像为导向,但我知道还有其他的。
准确地按照您的想法计算协方差矩阵的特征向量在计算上非常昂贵。您必须将图像的每个像素(或较大的随机样本)与 x,y 点相关联。
基本上,你可以这样做:
你可以利用它是定期采样的图像这一事实并计算它的矩(或“惯性轴”)。对于大图像来说,这会快得多。
举一个简单的例子,(我正在使用我的以前的答案的一部分,以防您发现它有用。 ..)
Just a quick note, there are several tools to fit a gaussian to an image. The only thing I can think of off the top of my head is scikits.learn, which isn't completely image-oriented, but I know there are others.
To calculate the eigenvectors of the covariance matrix exactly as you had in mind is very computationally expensive. You have to associate each pixel (or a large-ish random sample) of image with an x,y point.
Basically, you do something like:
You can instead make use of the fact that it's a regularly-sampled image and compute it's moments (or "intertial axes") instead. This will be considerably faster for large images.
As a quick example, (I'm using a part of one of my previous answers, in case you find it useful...)
稳健地拟合高斯函数可能很棘手。 IEEE 信号处理杂志上有一篇关于这个主题的有趣文章:
我在这里给出一维案例的实现:
http://scipy-central.org/item/28/2/fitting-a-gaussian-to-noisy-data-points
(向下滚动查看拟合结果)
Fitting a Gaussian robustly can be tricky. There was a fun article on this topic in the IEEE Signal Processing Magazine:
I give an implementation of the 1D case here:
http://scipy-central.org/item/28/2/fitting-a-gaussian-to-noisy-data-points
(Scroll down to see the resulting fits)
您尝试过主成分分析(PCA)吗?也许 MDP 包 可以轻松完成这项工作。
Did you try Principal Component Analysis (PCA)? Maybe the MDP package could do the job with minimal effort.