Color-Based Segmentation Using the L*a*b* Color Space

2 vues (au cours des 30 derniers jours)
giacomo
giacomo le 31 Oct 2017
Commenté : giacomo le 2 Nov 2017
Hi everyone. I'm trying to count the number of elements in this picture via color-based segmentation. I'm following the tutorial at this link: https://es.mathworks.com/help/images/examples/color-based-segmentation-using-the-l-a-b-color-space.html Anyway, in the demo he takes 'load coordinates' while I want to get 3 roipoly functions to get the thresholds for the three colors and then save them into 'region coordinates' so that the loop at line 14 (and the code) flows. Thanks.

Réponse acceptée

Akira Agata
Akira Agata le 1 Nov 2017
Looking at your image, there are obviously 4 colors --- blue, green, red and dark brown (=background). So I believe Color-Based Segmentation Using K-Means Clustering example page will be help. The following is an example of k-means-based clustering of your image.
% Read the image and convert to L*a*b* color space
I = imread('Crop.jpg');
Ilab = rgb2lab(I);
% Extract a* and b* channels and reshape
ab = double(Ilab(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
% Segmentation usign k-means
nColors = 4;
[cluster_idx, cluster_center] = kmeans(ab,nColors,...
'distance', 'sqEuclidean', ...
'Replicates', 3);
% Show the result
pixel_labels = reshape(cluster_idx,nrows,ncols);
imshow(pixel_labels,[]), title('image labeled by cluster index');
  1 commentaire
giacomo
giacomo le 2 Nov 2017
Thank you! After the segmentation I created a code to interactively select the diameter of the elements' incircle.
>> h = ginput(2);
diameter = sqrt((h(2)-h(1))^2+(h(4)-h(3))^2);
BlobArea = 3.14*(diameter^2)/4;
How can I count the number of blobs? I know there are examples by Image Analyst but I cannot adapt them to my case. I'd also like to use the infos about the incircle so that all blobs with area < BlobArea won't be counted, while blobs with much bigger area than that (see objects sharing borders with eachother) will have their area divided by BlobArea to get a more reasonable value of number of blobs. Thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Segmentation and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by