draw rectangle on extracted region
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone, I have extracted the moving region by subtracting the video frames. Now I want to draw a rectangle over the extracted part but the problem is the pixels are not connected, thus I can't use regionprops() because it gives several boxes due to disconnected pixels. I have inserted the image where I want to draw rectangle over the extracted moving pendulum area. How can I do this. Please help. Thanks.
0 个评论
回答(1 个)
Walter Roberson
2015-6-21
vertprofile = any(YourImage>0,1);
bbox_x_low = find(vertprofile, 1, 'first');
bbox_x_high = find(vertprofile, 1, 'last');
horzprofile = any(YourImage>0,2);
bbox_y_low = find(horzprofile, 1, 'first');
bbox_y_high = find(horzprofile, 1, 'last');
The way to proceed from there depends upon how you are going to draw the rectangle.
1 个评论
Image Analyst
2015-6-21
By the way, Nataliya, you can use regionprops, you'd just get all the bounding boxes and just use max and min like Walter shows, Or you could call bwconvull() to get just one region then call regionprops(). But unless you're calling regionprops for some other reason, I'd just go with Walter's method.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!