Extracting silhouette from depth
Hi I have a depth image, I want to extract a person (person) from it. I used pixel thresholds like this:
for i=1:240
for j=1:320
if b(i,j)>2400 || b(i,j)<1900
c(i,j)=5000;
else
c(i,j)=b(i,j);
end
end
end
but there is a part. Is there a way to remove this?
Original_image:
Extracted_silhouette:
source to share
[dzx dzy] = gradient( depth_map ); %// horizontal and vertical derivatives of depth map
n = cat( 3, dzx, dzy, ones(size(dzx)) );
n = bsxfun( @rdivide, n, sqrt( sum( n.^2, 3 ) ) ); %// normalize to unit length
An easy way could be a threshold
e = abs( n(:,:,3) ) < 1e-2;
Result with
A more sophisticated method of getting silhouette from border can be found in this answer .
source to share
This is difficult to do at the threshold because the couch is at the same depth as the top of the person. Do you need to segment the whole person, or would it be sufficient to segment the upper body? In the latter case, you can try using vision.CascadeObjectDetector, which is a Computer Vision system toolbar, to detect the top of the face in an RGB image.
source to share
Building on @Shai's work above , you can take the thresholding output and then apply a border to the THAT image. Below is an example that you can feed to [YOUR_IMAGE] from the results of the previous steps, and then change the [ADJUST] value until only a person is selected.
This code looks for borders by size and will not select anything larger than the value you entered. Simple, but it works for me. Hope this helps.
boundaries = bwboundaries([YOUR_IMAGE]);
numberOfBoundaries = size(boundaries)
if (size(boundaries) < [ADJUST])
for k = 1 : numberOfBoundaries
thisBoundary = boundaries2{k}
plot(thisBoundary(:,2), thisBoundary(:,1), 'b', 'LineWidth', 2);
end
end
source to share