SimaGuanxing
SimaGuanxing

Reputation: 691

In Matlab, How to divide multivariate Gaussian distributions to separate Gaussians?

I have an image with multivariate Gaussian distribution in histogram. I want to segment the image to two regions so that they both can follow the normal distribution like the red and blue curves shows in histogram. I know Gaussian mixture model potentially works for that. I tried to use fitgmdist function and then clustering the two parts but still not work well. Any suggestion will be appreciated. enter image description hereenter image description here enter image description here enter image description here

Below is the Matlab code for my appraoch.

% Read Image
I = imread('demo.png');
I = rgb2gray(I);
data = I(:);

% Fit a gaussian mixture model
obj = fitgmdist(data,2);
idx = cluster(obj,data);
cluster1 = data(idx == 1,:);
cluster2 = data(idx == 2,:);

% Display Histogram
histogram(cluster1)
histogram(cluster2)

Upvotes: 5

Views: 3972

Answers (2)

Brendan Frick
Brendan Frick

Reputation: 1025

Your solution is correct

The way you are displaying your histogram poorly represents the detected distributions.

  1. Normalize the bin sizes because histogram is a frequency count
  2. Make the axes limits consistent (or plot on same axis)

These two small changes show that you're actually getting a pretty good distribution fit.

histogram(cluster1,0:.01:1); hold on;
histogram(cluster2,0:.01:1);

Hists

Re-fit a gaussian-curve to each cluster

Once you have your clusters if you treat them as independent distributions, you can smooth the tails where the two distributions merge.

gcluster1 = fitdist(cluster1,'Normal');
gcluster2 = fitdist(cluster2,'Normal');

x_values = 0:.01:1;
y1 = pdf(gcluster1,x_values);
y2 = pdf(gcluster2,x_values);
plot(x_values,y1);hold on;
plot(x_values,y2);

Gaussian

Upvotes: 5

kri
kri

Reputation: 83

How are you trying to use this 'model'? If the data is constant, then why dont you measure, the mean/variances for the two gaussians seperately?

And if you are trying to generate new values from this mixed distribution, then you can look into a mixture model with weights given to each of the above distributions.

Upvotes: -2

Related Questions