You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by lu...@free.fr on 2009/08/17 14:53:29 UTC

[math] Re: 2D Gaussian Fit

Hi Jean-François,

First, please use a [math] marker in the subject line when asking something about
commons-math. This mailing list is shared by all commons components so these markers
help filtering messages.

----- "Jean-Francois Daune" <Je...@iba-group.com> a écrit :

> Is it possible to perform a 2D Gaussian fit (giving center_x,
> center_y, sigma_x, sigma_y, theta) with Commons Math?

Yes it is possible. You will have to use the optimization package, and most probably
the LevenbergMarquardtOptimizer class from the general subpackage. This will be the main
algorithm that will perform the fit. You should implement your problem as your own class
implementing the DifferentiableMultivariateVectorialFunction interface (i.e. a class
that provides a "double[] value(double[] point)" method and a "MultivariateMatrixFunction
jacobian()" method (which itself wraps another value function). In your case, the point[]
parameters for both value functions will be the parameters of your fit, i.e. center_x, center_y,
sigma_x, sigma_y and theta. You can look in the junit tests of the library. In the
LevenbergMarquardtOptimizerTest class there is a Circle internal class that implements a fitting
problems for observed points that should lie on a circle. You can use this as an example to
implement your own Gauss2D class.

If this information is not sufficient, do not hesitate to ask and I'll try to provide more.

Luc


> 
> Any help is appreciated.
> 
> J-F
> 
> The contents of this e-mail message and any attachments are intended
> solely for 
> the recipient (s) named above. This communication is intended to be
> and to 
> remain confidential and may be protected by intellectual property
> rights. Any 
> use of the information contained herein (including but not limited to,
> total or 
> partial reproduction, communication or distribution of any form) by
> persons 
> other than the designated recipient(s) is prohibited. Please notify
> the sender 
> immediately by e-mail if you have received this e-mail by mistake and
> delete 
> this e-mail from your system. E-mail transmission cannot be guaranteed
> to be 
> secure or error-free. Ion Beam Applications does not accept liability
> for any 
> such errors. Thank you for your cooperation.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [math] Re: 2D Gaussian Fit

Posted by Ted Dunning <te...@gmail.com>.
Depending on what you mean by a 2D Gaussian fit, you may just need to
compute mean and covariance matrix to get what you need.

Remember that a 2D Gaussian needs center{x,y} and FOUR parameters for
variance, three of which are independent.  The reason is that you can have a
Gaussian that is long and thin, but oriented at an arbitrary angle.  If x is
a vector containing a position, then the multi-variate Gaussian is typically
written as

         N(x | m, S) = Z exp( - (x-m)' R (x-m) )

R is the inverse of the covariance matrix \Sigma and the normalizing
constant Z = 1 / \sqrt((2 pi)^n | \Sigma |).

With enough data, you can get fine estimates of these quantities directly,
without any optimization.  With less data, you need to have a bit of a prior
expectation, but you can still get decent estimates.

On Mon, Aug 17, 2009 at 5:53 AM, <lu...@free.fr> wrote:

> Hi Jean-François,
>
> First, please use a [math] marker in the subject line when asking something
> about
> commons-math. This mailing list is shared by all commons components so
> these markers
> help filtering messages.
>
> ----- "Jean-Francois Daune" <Je...@iba-group.com> a écrit :
>
> > Is it possible to perform a 2D Gaussian fit (giving center_x,
> > center_y, sigma_x, sigma_y, theta) with Commons Math?
>
> Yes it is possible. You will have to use the optimization package, and most
> probably
> the LevenbergMarquardtOptimizer class from the general subpackage. This
> will be the main
> algorithm that will perform the fit. You should implement your problem as
> your own class
> implementing the DifferentiableMultivariateVectorialFunction interface
> (i.e. a class
> that provides a "double[] value(double[] point)" method and a
> "MultivariateMatrixFunction
> jacobian()" method (which itself wraps another value function). In your
> case, the point[]
> parameters for both value functions will be the parameters of your fit,
> i.e. center_x, center_y,
> sigma_x, sigma_y and theta. You can look in the junit tests of the library.
> In the
> LevenbergMarquardtOptimizerTest class there is a Circle internal class that
> implements a fitting
> problems for observed points that should lie on a circle. You can use this
> as an example to
> implement your own Gauss2D class.
>
> If this information is not sufficient, do not hesitate to ask and I'll try
> to provide more.
>
> Luc
>
>
> >
> > Any help is appreciated.
> >
> > J-F
> >
> > The contents of this e-mail message and any attachments are intended
> > solely for
> > the recipient (s) named above. This communication is intended to be
> > and to
> > remain confidential and may be protected by intellectual property
> > rights. Any
> > use of the information contained herein (including but not limited to,
> > total or
> > partial reproduction, communication or distribution of any form) by
> > persons
> > other than the designated recipient(s) is prohibited. Please notify
> > the sender
> > immediately by e-mail if you have received this e-mail by mistake and
> > delete
> > this e-mail from your system. E-mail transmission cannot be guaranteed
> > to be
> > secure or error-free. Ion Beam Applications does not accept liability
> > for any
> > such errors. Thank you for your cooperation.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> > For additional commands, e-mail: user-help@commons.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>


-- 
Ted Dunning, CTO
DeepDyve