Separate the foreground from background in an image

I'm taking a gray scale image and the background is white. How can I get the foreground i.e. the object and remove the background. I want to do all this without any change in the pixel values, so that I can use it for future use.
Can anyone please sort out this problem ........

 Accepted Answer

Let "Th" be the threshold level between foreground and background -- the point at which the gray of the foreground has become bright enough white to be considered background. Then,
mask = YourImage < Th;
will be a logical array "mask" that is true for the foreground locations.
That's as far as you can get without changing any pixel values.
What kind of data structure were you thinking of that had the background removed? MATLAB cannot have irregularily-shaped arrays. You can construct rectangular arrays that have the original values in all of the foreground locations, but something has to be in the background locations.

1 Comment

I got it. Thank you very much for giving me reply with clear description.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!