如何在Matlab中为不连续区域应用边界框 [英] How can I apply bounding box for a discontiguous region in Matlab
问题描述
我正在尝试为以下示例中的不连续区域应用边界框.我在regionprops
的Matlab帮助文档中找到了一些内容,但没有说明有关操作方法的任何内容.我需要最小的Box,它可以包含图像中的所有斑点.
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.
推荐答案
默认情况下,当引入logical
类型输入掩码时, bwlabel
设置为掩码,并计算输入掩码的每个连接组件的属性.
在您的情况下,这不是理想的行为,因为您希望将所有白色像素都视为同一组件的一部分.要克服此默认行为,您只需要将输入掩码从logical
强制转换为其他数据类型.
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 );
结果来自
这篇关于如何在Matlab中为不连续区域应用边界框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!