using the fitgmdist function on an image

5 views (last 30 days)
Newman
Newman on 27 Sep 2015
Edited: Newman on 28 Sep 2015
Hi all, I want to cluster my binary image using the Gaussian mixture model (EM algorithm).How to first of all use the fitgmdist to fit a GMM into my binary image? It uses a mean and variance and prior probability on its own in the official mat lab example .SO in the case of an image (binary) will that correspond to the mean variance of the entire image ???or some particular rows and columns of the image?? how to decide that also ??kindly help!!
I=imread(('sil10340.pbm'));
%img is the name of the image
% k is the no of clusters
%read file
I = 255 * uint8(I);
I=im2double(I);
K=10;
%choose indices of 'white' pixels as coordinates of data
[datax datay]=find(I);
%cluster data into 10 clumps
[cInd, c] = kmeans([datax datay], K, 'EmptyAction','singleton',...
'maxiter',1000,'start','cluster');
obj = fitgmdist(I,K,'Regularizationvalue',0.1);
idx = cluster(obj,I);
cluster1 = I(idx == 1,:);
cluster2 = I(idx == 2,:);
figure;
gscatter(datay,-datax);
hold on
h1=scatter(cluster1(:,1),cluster1(:,2),10,'r.');
h2=scatter(cluster2(:,1),cluster2(:,2),10,'g.');
% scatter(obj.mu(:,2),-obj.mu(:,1),20,'ko'); %same funky coordinates
% scatter(c(:,2),-c(:,1),20,'k+'); %same funky coordinates
legend([h1 h2],'Cluster 1','Cluster 2','Location','NW')

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!