Image Segmentation Bounding Box
8 views (last 30 days)
Show older comments
I have a image that contains the topview of an animal. The objective is to isolate the animal from the image. The original image can be seen in the left upper picture form the following figure:
I do some preprocessing steps that lead to the image (inverseBW_filtered) shown in the right lower corner. Using this image, I run the following line of code:
stats = regionprops(inverseBW_filtered, 'BoundingBox', 'Centroid');
Sadly, just one bounding box is found (plotted as the red box). I would have expected to get a few boxes at least with one of them surrounding the animal. Can I get some suggestions how to make sure that the animal gets segmented using regionprops (or any other technique)?
3 Comments
Answers (2)
Pratham Shah
on 1 Jun 2023
Hi!
To get the bounding box around the animal; If you know the area animal the animal will cover use blobAnalysis function. To remove the white pixels from bottom-right corner you can use 'imclearborder' morphological function.
newBW=imclearborder(ImgBW,8); %You can change '8' depending on your application
blob = vision.BlobAnalysis('BoundingBoxOutputPort', true,...
'AreaOutputPort', false, 'CentroidOutputPort', false, ...
'MinimumBlobArea', 50);
box= step(blob, newBW);
Output = insertShape(Image, 'Rectangle', box, 'Color', 'red','Linewidth',2);
Image Analyst
on 1 Jun 2023
Edited: Image Analyst
on 1 Jun 2023
If you don't have a background image, you can create one by taking the mode of every pixel over all frames in the video (or as many of them as you can fit in memory).
You can even get an estimate for the background if you can hand trace the animal in one frame. Then you can use regionfill to estimate the background underneath the animal. Demos for hand tracing regions are attached.\
It's kind of weird that the height of the animal is both higher and lower than the background at the left of the scene. Do you have a visible light image of the scene you can share? The animal looks like it's shaped like a trough.
2 Comments
Image Analyst
on 1 Jun 2023
If you have an empty/no-animal image, then you can find the animal by using imabsdiff followed by thresholding.
diffImage = imabsdiff(emptyFrame, currentFrame);
mask = diffImage > someValue; % Threshold to find "tall" things in the scene.
% Take largest blob only.
mask = bwareafilt(mask, 1);
See Also
Categories
Find more on 3-D Volumetric Image Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!