[英]How can I apply bounding box for a discontiguous region in Matlab
我正在嘗試為以下示例中的不連續區域應用邊界框。 我在有關regionprops
Matlab幫助文檔中找到了一些內容,但是它沒有說明有關如何執行操作的任何內容。 我需要可以包含圖像中所有斑點的最小Box。
默認情況下,當引入logical
類型輸入掩碼時, regionprops
自動將bwlabel
應用於掩碼,並為輸入掩碼的每個連接組件計算屬性。
在您的情況下,這不是理想的行為,因為您希望將所有白色像素都視為同一組件的一部分。 要克服此默認行為,您只需要將輸入掩碼從logical
類型轉換為其他數據類型。
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 );
結果與
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.