MATLAB: How to fill inside of the object

gesture recognitionhandImage Processing Toolbox

Hello every one,
I have one hand image(binary), which after doing segmentation i got the image with edges and now i want to fill inside of the hand which can see in the second following image.
I used imfill but it didnt change anything.
I will appreciate if anyone can help me to do it.
thanks

Best Answer

You need to draw a line across the bottom to close off the arm before you fill it.
% Make tempoprary line.
binaryImage(end, :) = true;
% arm is sealed off. Now we can fill.
binaryImage = imfill(binaryImage, 'holes');
% Erase temporary line.
binaryImage(end,:) = false;