the problem of image segementation

Hello, everyone. I read the demo from help about color-based segmentation using L*a*b space. First, it acquires the image and then it calculate color value in L*a*b space for each region. But I can not understand the code for classification.
if true
%for count = 1:nColors
distance(:,:,count) = ( (a - color_markers(count,1)).^2 + ...
(b - color_markers(count,2)).^2 ).^0.5;
[~, label] = min(distance,[],3);
label = color_labels(label);
end
end
Could U explain the function of min here? I know it needs to find the nearest distance, but why the first parameter in the [ ] is ~? Thanks in advance. Best, Helena.

Réponses (1)

Nicolas Schmit
Nicolas Schmit le 12 Oct 2017

0 votes

In this problem, you are not interested in the value of the minimum distance itself, but in where the minimum distance occurs in your distance array. The command
[~, label] = min(distance,[],3);
returns in 'label' the index of the minimum value in the distance array. ~ is a command to ignore the first value returned by the min() function, which is the minimum value of the distance array. Here, you ignore this value since you do not need it.

3 commentaires

Y
Y le 12 Oct 2017
Tx, so this sentence only cares about the label which uses to perform classification. Get it!
Image Analyst
Image Analyst le 12 Oct 2017
A better way than squaring and using min() would be to use a discriminant classifier, classify(). If you have the Statistics and Machine Learning Toolbox and would like a demo, let me know. Another way is to use rgb2ind().
Y
Y le 13 Oct 2017
I would like a demo about that. Tx!!

Cette question est clôturée.

Question posée :

Y
Y
le 12 Oct 2017

Clôturé :

le 20 Août 2021

Community Treasure Hunt

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

Start Hunting!