MATLAB: Extract object from depth image.

extract objectforeground subtractImage Processing Toolboximage segmentationregion of interest

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.

Best 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