Asked by Nidhi
on 25 Jun 2012

Hello,

Below I have given 5 points. In each point mu, sigma and mixp is given. Gmdistribution is calculated for each . Changing of mu and sigma values do not make any change in the answer. But if I change the mixp values then the distribution value changes. Why does the change in mean and sigma doesnot affect the gmdistribution?

1. mu = [1 2;-3 -5]; Sigma = [2 0; 0 .5],[1 0; 0 1]; mixp = ones(1,2)/2; gm = gmdistribution(mu,Sigma,mixp) ans= Sigma = 2.0000 0 0 0.5000 gm = Gaussian mixture distribution with 2 components in 2 dimensions Component 1: Mixing proportion: 0.500000 Mean: 1 2

Component 2: Mixing proportion: 0.500000 Mean: -3 -5

2. I have changed the value of mixp

mu = [1 2;-3 -5]; Sigma = [2 0; 0 .5],[1 0; 0 1]; mixp = ones(1,2); gm = gmdistribution(mu,Sigma,mixp) ans= Sigma = 2.0000 0 0 0.5000 gm = Gaussian mixture distribution with 2 components in 2 dimensions Component 1: Mixing proportion: 0.500000 Mean: 1 2

Component 2: Mixing proportion: 0.500000 Mean: -3 -5

3. I have changed the value of mixp again

mu = [1 2;-3 -5]; Sigma = [2 0; 0 .5],[1 0; 0 1]; mixp = [3 4]; gm = gmdistribution(mu,Sigma,mixp) ans= Sigma = 2.0000 0 0 0.5000 gm = Gaussian mixture distribution with 2 components in 2 dimensions Component 1: Mixing proportion: 0.428571 Mean: 1 2

Component 2: Mixing proportion: 0.571429 Mean: -3 -5

4. I have changed the value of sigma. The mixing proportion remains the same as above.

mu = [1 2;-3 -5]; Sigma = [8 0; 0 .5],[1 0; 0 1]; mixp = [3 4]; gm = gmdistribution(mu,Sigma,mixp) Sigma = 8.0000 0 0 0.5000 gm = Gaussian mixture distribution with 2 components in 2 dimensions Component 1: Mixing proportion: 0.428571 Mean: 1 2

Component 2: Mixing proportion: 0.571429 Mean: -3 -5 5. I have changed the value of mean but the mixing proportion doesnot change.

mu = [7 2;-3 -5]; Sigma = [8 0; 0 .5],[1 0; 0 1]; mixp = [3 4]; gm = gmdistribution(mu,Sigma,mixp)

Sigma =

8.0000 0 0 0.5000

gm =

Gaussian mixture distribution with 2 components in 2 dimensions Component 1: Mixing proportion: 0.428571 Mean: 7 2

Component 2: Mixing proportion: 0.571429 Mean: -3 -5

Thanks,

Nidhi

*No products are associated with this question.*

Answer by Tom Lane
on 25 Jun 2012

Accepted answer

There are two ways to create a gmdistribution. One is by specifying the mean, covariance, and mixing proportion. The result is a distribution with the parameters you specified. That seems to be what is happening in your case. The resulting objects have the means that you specify. The mixing proportions are also the same as the ones you provided, but they are normalized to sum to 1 (so they are real proportions, not just relative sizes.

The other way is to fit to data using the gmdistribution.fit function.

So what is confusing about the output you quote? It may be the normalization of the mixing proportions. My only other idea is that you seem to be trying to specify two covariance matrices, but that's not working. You have

Sigma = [8 0; 0 .5],[1 0; 0 1];

This is actually two statements, one assigning a 2-by-2 matrix to Sigma and the other simply creating a second matrix and discarding it. You may be intending this:

>> Sigma = cat(3,[8 0; 0 .5],[1 0; 0 1]) Sigma(:,:,1) = 8.0000 0 0 0.5000 Sigma(:,:,2) = 1 0 0 1

Answer by Nidhi
on 26 Jun 2012

Thanks a lot. Actually the reason for asking about gmdistribution was that I was making a program using gmdistribution. But, it is giving error at the gmdistribution command. So, I wanted to clear the concept. I saw the algo of this on internet itself and tried it.

The program is :

frame20 = double(imread('image6.jpg'));

[rows,cols,bands] = size(frame20);

skin_detection = zeros(rows, cols);

for row = 1:rows

for col = 1:cols

red = frame20(row, col, 1);

green = frame20(row, col, 2);

blue = frame20(row, col, 3);

r = gmdistribution(red_mean, red_std, red); red_pr=pdf(r,red);

g = gmdistribution(green_mean, green_std, green) green_pr=pdf(g,green);

b = gmdistribution(blue_mean, blue_std, blue); blue_pr=pdf(b,blue);

prob = red_pr .* green_pr .* blue_pr; skin_detection(row, col)= prob;

end

end

This is giving error:

??? Error using ==> gmdistribution.gmdistribution>gmdistribution.gmdistribution at 158 The mixing proportions must be positive.

Error in ==> trial_gauss_fullimage at 51 g = gmdistribution(green_mean, green_std, green); Error in ==> trial_gauss_fullimage at 52 green_pr=pdf(g,green);

The name of my file is trial_gauss_fullimage.

In this the mean and std values of red, green and blue it calculated and these are 1*1 matrix i.e. constant one value eg. red_mean is 237.2865 and red_std is 13.8627. Same holds for red also.

I hope I have been able to explain my problem. If you can help me out it would be great.

Thanks,

Nidhi

Show 3 older comments

Nidhi
on 30 Jun 2012

Thanks a lot. You have been very cooperative. Please see the link below: http://vlm1.uta.edu/~athitsos/courses/cse6367_spring2012/lectures/07_skin/skin_detection.pdf

I have used the this algo.

I am getting confused between gmdistribution, normalpdf and cdf. whichh one do I have to use in this program.

Can you pl. identify this from the algo given on this link.

Thanks,

Nidhi

Tom Lane
on 30 Jun 2012

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments