image segmentation by k mean

1 view (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
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
Edited: 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.

Community Treasure Hunt

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

Start Hunting!