如何在Matlab中为不连续区域应用边界框 [英] How can I apply bounding box for a discontiguous region in Matlab

查看:339
本文介绍了如何在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类型输入掩码时,

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆