Image Segmentation Bounding Box
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Pratham Shah
2023-6-1
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
2023-6-1
编辑:Image Analyst
2023-6-1
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 个评论
Image Analyst
2023-6-1
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);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!