How to create a silhouette
Show older comments
Hi all,
I've been trying to create a silhouette with the following code;
function S = getsilhouette( im )
%GETSILHOUETTE - find the silhouette of an object centered in the image
[h,w,d] = size(im);
% Initial segmentation based on more red than blue
S = im(:,:,1) > (im(:,:,3)-2);
% Remove regions touching the border or smaller than 10% of image area
S = bwareaopen(S, ceil(h*w/10));
squeeze(S);
% % Now remove holes < 1% image area
S = ~bwareaopen(~S, ceil(h*w/100));
And this is what I get as an output;

I was wondering if anyone had any ideas to remove the base?
Many thanks and cheers for reading
Adam
5 Comments
Cedric
on 13 Apr 2013
Could you grab an image without the object (but with the support)? This could be a basis for extracting whatever object you place on the support..
Ian
on 13 Apr 2013
Yes, that's the idea. Any pixel of the image including the object that is not "close enough" to the corresponding pixel of the image with no object, defines the object.
Now I have little experience in image processing; I would be able to do it my way, but I am unable to tell you how to do it using proper techniques, so I would be interested as well in having Image Analyst's take on this matter.
PS: "my way" would be to set thresholds on the norm of differences between corresponding channels associated with both the image without and the image with the object.
Image Analyst
on 14 Apr 2013
Edited: Image Analyst
on 14 Apr 2013
If you can get a "blank shot" - an image without the object of interest in it - then that is certainly the way to go. Then just subtract and threshold.
diffImage = abs(double(grayImage) - double(backgroundImage));
binaryImage = diffImage > 4; % or whatever value you want.
You might want to fill holes too:
binaryImage = imfill(binaryImage, 'holes');
Cedric
on 14 Apr 2013
Thank you for the update!
Accepted Answer
More Answers (0)
Categories
Find more on Video Formats and Interfaces in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!