MATLAB Answers

image segmentation by k mean

6 views (last 30 days)
mangood UK
mangood UK on 14 Jun 2013
dear member
i have these image that captured by a webcam
i try to segment the image to get any object using k mean with k=2 with ground all ways black
the problem is when i execute the k mean on image on real time with square or circle object the result binary image is perfect
but when both objects(square and circle) appear in same image the square object is disappear or the k mean consider it as background not as foreground object
as ground is black all the time and the light only change on my room what is the best pre processioning that must done before the k mean applied so any object will appear in binary image
best regards

Answers (1)

Walter Roberson
Walter Roberson on 14 Jun 2013
Edited: Walter Roberson on 14 Jun 2013
Suppose the circle is intensity 255, and suppose the background is intensity 0. If the rectangle is intensity 128 to 255, it will be closer to the circle's intensity and classified with it, but if the rectangle is intensity 1 to 127 then it would be closer to the background's intensity and so clustered with it. My estimate by eye is that the rectangle is less than half bright.
The problem would not occur when the circle is not there, because then the only two values would be 0 and the rectangle's intensity and those are fairly distinct.
What you should do is threshold against a low level such as (say) 16 and say that anything below that level is background.
BW = IM > Threshold;
and then analyze BW. Or alternately,
BW = IM > Threshold;
PartialIM = IM(BW);
kmeans(PartialIM(:), 2)

  4 Comments

Show 1 older comment
Image Analyst
Image Analyst on 14 Jun 2013
It means that by using thresholding you can make sure the circle and the rectangular objects are both classified as "foreground" - they're both in the "foreground" cluster instead of the medium gray things being classified incorrectly as part of the "background" cluster. I don't see any need to use kmeans at all in this situation. Segmentation via thresholding is all you need and is the simplest approach.
mangood UK
mangood UK on 14 Jun 2013
dear Walter Roberson
your solution work both object appear but if any light is focus on black ground the method will consider it as foreground as figure below
dear Image Analust
i tried from trying many threshold values can i make a pre processing before the threshold to solve the problem
Image Analyst
Image Analyst on 14 Jun 2013
That binary image doesn't look correct. What threshold value did you use? Try my interactive thresholding app: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

Sign in to comment.

Sign in to answer this question.