Extract object from depth image.

I have 2 depth images where the a rectangular shaped object is present. I’d like to extract the rectangular object from the images. I have attached here the original depth images and below I show the converted 8 bit image for the purpose of visualization.
Image-1:
Image-2:
I think I have to use binary image and then use bounding box to extract the object. However, I can’t figure out how exactly I should proceed with the coding.
It would be great to have any suggestions.

 Accepted Answer

You can simply threshold at whatever depths you believe the object to be at, then call regionprops():
binaryImage = depthImage > depth1 & depthImage < depth2;
binaryImage = bwareafilt(binaryImage, 1); % Extract largest blob only.
props = regionprops(binaryImage, 'BoundingBox');
boundingBox = props.BoundingBox

4 Comments

Thanks a lot! It works nicely.
what is depth 1 and depth 2 here?
It's whatever you want them to be. Like if you want depths or distances between 160 and 170 cm, then they'd be 160 and 170. To get surfaces at a certain depth/distance you must know what depths/distances you're interested in of course. Otherwise you have the entire image with all depths.
That code should work to read whatever variables were in 'depth.mat' into a structure called depthImage. It's not an image but a structure. Leave the semicolon off to see what variables are in it. Maybe the variable was called depthImage, so you'd do:
storedStructure = load('depth.mat')
depthImage = storedStructure.depthImage;

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!