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.
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)
The way you are displaying your histogram poorly represents the detected distributions.
histogram
is a frequency countThese 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);
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With