Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 372
SimaGuanxing Avatar asked Oct 18 '22 10:10

SimaGuanxing


1 Answers

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

like image 193
Brendan Frick Avatar answered Oct 21 '22 07:10

Brendan Frick