How can I apply bounding box for a discontiguous region in Matlab

青春壹個敷衍的年華 提交于 2019-12-13 21:29:36

问题


I am trying to apply a bounding box for the discontiguous region in the sample below. I found something in Matlab help docs on regionprops but it did not explain anything about how to do it. I need the smallest Box that can contain all the blobs in the image.


回答1:


By default, when introduced with a logical type input mask, regionprops automatically apply bwlabel to the mask and computes properties for each connected component of the input mask.
In your case, this is not a desirable behavior, since you want all the white pixels to be treated as part of the same component. To overcome this default behavior you simply need to cast the input mask from logical to other data type.

st = regionprops( uint8( BW ), 'BoundingBox' ); %// cast to uint8
rect = st.BoundingBox; %// the bounding box of all white pixels

%// display the results
figure;
imshow( BW, 'border', 'tight' ); 
hold on;
rectangle('Position', rect, 'EdgeColor', 'r', 'LineWidth', 1.5 );

Resulting with



来源:https://stackoverflow.com/questions/27342380/how-can-i-apply-bounding-box-for-a-discontiguous-region-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!