MATLAB: Segmentation of foreground and background objects from an image code gray scale and color image.pease help me with code

Image Processing Toolboximage segmentation for background and foreground

an algorithm that can take gray scale and color image as
an input and perform segmentation of foreground and background objects in that image.

Best Answer

That pretty much describes all of image segmentation and tens of thousands of algorithm do that. I don't even have access to them all. You'll have to be more specific - it's just too vague to even give an answer other than "You can use image processing".
Here, read this: http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer then attach an image and say what you want to segment since for many images what is considered foreground is a matter of opinion. It may have to do with color rather than distance from the camera for example. If you have an image of apples far away, and blueberries close to the camera and they're both on a table, can you tell me what's the foreground or what you want to measure? No. There's no obvious answer.