1

While initialising the particles, i need to add some gaussian noise to it. For example

particle.x(i) = rect(1)+mgd(1,1,0,10);

here rect(1) gives the position, and mgd function is providing the noise

The details about the mgd function are:

  • Function x=mgd(N,d,rmean,covariance)
  • Generates a Multivariate Gaussian Distribution
  • Usage x=mgd(N,d,mu,sigmax)
  • This function generates N samples from a d-dimension Gaussian distribution

My value of N and d are always 1, How can I implement the mgd function in opencv c++?

Simson
  • 829
  • 6
  • 16
Pruthvi P
  • 536
  • 1
  • 7
  • 31
  • 1
    Maybe have a look at 'related link' http://stackoverflow.com/questions/6142576/sample-from-multivariate-normal-gaussian-distribution-in-c?rq=1 about your question: is you sigma uniform in all dimensions? – Micka Jun 11 '14 at 09:24
  • @Micka Yes, its uniform. Is there simple or inbuilt function, because i m not able to understand anything from the answers in that link – Pruthvi P Jun 11 '14 at 09:30
  • unfortunately the in-built openCV functions only create univariate values as far as I know and I don't know whether multivariate distribution sampling with uniform sigma can be reduced to multiple univariate distributions... sorry – Micka Jun 11 '14 at 09:36
  • 1
    @Micka that's not true, you can initialize anything that fits into an `cv::InputArray` with the OpenCV rng functions.. check my answer ;) – Яois Jun 11 '14 at 09:50
  • @KeillRandor I thought that would only create d univariate distrubtion values, glad to know it better now =) – Micka Jun 11 '14 at 10:24

2 Answers2

1

Take a look at standard library "random", it includes methods for different distributions, including normal distribution.

In the case of uncorrelated variables, you can use independent 1D random number for each dimension (see KeillRandor's answer), otherwise it is not correct. For implementation you can look at MATLAB's code, to do it, type in script editor

mvnrnd

then right mouse click on just typed command and select open mvrnd in context menu. You'll see the MATLAB code for mvnrnd function.

Andrey Smorodov
  • 10,649
  • 2
  • 35
  • 42
1

OpenCV comes with a nice Random Number Generator class and also many useful functions. To initialize a d-dimensional vector with random gaussian noise, just do:

int d = 10; // dimension
float m = 0, cov = 0.1; // mean and covariance
vector<float> X(d,.0f); // your d-dimensional vector
cv::randn(X,m,cov); // <-

Cheers!

Яois
  • 3,838
  • 4
  • 28
  • 50