Applying Gaussian Mixture Models to grayscale images

Suppose I have a grayscale image such as imshow('rice.png') and I want to cluster the grains using Gaussian Mixture Models (gmdistribution).
Is there any better way to do it than generating a location matrix of high intensity coordinates and applying gmdistribution.fit? Or is there a matlab filter that will automatically transform grayscale/intensity data into data needed for fitting a Gaussian mixture model in matlab?
thanks

Answers (1)

If you want to cluster the location of the grain centroids, then find the centroids with regionprops, and then call fitgmdist()
binaryImage = grayImage > somethreshold;
labeledImage = bwlabel(binaryImage);
props = regionprops(labeledImage, 'Centroid');
allCentroids = [props.Centroid];
xCentroids = allCentroids(1:2:end);
yCentroid = allCentroids(2:2:end);
% Plot centroids over the displayed image
hold on;
plot(xCentroids, yCentroids, 'r+', 'MarkerSize', 20, 'LineWidth', 2);
Then call fitgmdist():
GMModel = fitgmdist([xCentroids, yCentroids], numClusters);

Asked:

on 28 Jan 2017

Answered:

on 29 Jan 2017

Community Treasure Hunt

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

Start Hunting!