Alfatau
Alfatau

Reputation: 243

OpenCV gaussian curve fitting

I'm looking for fitting a Gaussian curve using OpenCV. I can have 1D or 2D Mat, and I'd like to calculate the Gaussian parameters of the best Gaussian fit over the matrix. However, I'd like to be able to fix some parameter (e.g. the Gaussian mean or variance). The 1D model I'd like to fit is the following:

y = a + (b - a) * exp( -( x - c )/( 2 * d^2 ) )

In the case of 2D Mat, the model is the same of a multi-variate Gaussian function.

Has OpenCV some implementation suitable for my fitting needs? If yes, can you provide an example or some useful links? Thank you in advance.

Upvotes: 1

Views: 6027

Answers (2)

Vlad
Vlad

Reputation: 4525

Fitting a Gaussian curve simply means calculating its parameters which in 1D case are scalar mean and variance. Mean = sum(Xi)/n, variance = sum(Xi-mean)^2/(n-1), where ^2 means squared. This gets more interesting for 2D case. Mean is still calculated in the same way but it becomes a 2D vector. Instead of variance you calculate a covariance matrix like this. It is 2x2 matrix.

Upvotes: 3

sansuiso
sansuiso

Reputation: 9389

There's nothing to do that in OpenCV. However, if you derive the equations (Hessian matrix, etc.) you can easily implement some Levenberg-Marquardt estimation procedure with the cv::Mat matrix type.

Upvotes: 0

Related Questions