MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   bwboundaries-在MATLAB中,预处理 (https://www.labfans.com/bbs/showthread.php?t=26178)

poster 2019-12-14 20:13

bwboundaries-在MATLAB中,预处理
 
我只想跟踪灰色图像中的边界。我遇到了两次区域边界问题。我如何只获得一个边界并位于边缘像素的中心。在下面的示例中,我得到了两个区域4、30。但是我只需要(4)。要获得该图像需要进行哪些图像预处理。

示例:请参阅第4,30区

BW = imread('blobs.png'); [B,L,N,A] = bwboundaries(BW); figure, imshow(BW); hold on; colors=['b' 'g' 'r' 'c' 'm' 'y']; for k=1:length(B) boundary = B{k}; cidx = mod(k,length(colors))+1; plot(boundary(:,2), boundary(:,1),... colors(cidx),'LineWidth',2); %randomize text position for better visibility rndRow = ceil(length(boundary)/(mod(rand*k,7)+1)); col = boundary(rndRow,2); row = boundary(rndRow,1); h = text(col+1, row-1, num2str(L(row,col))); set(h,'Color',colors(cidx),... 'FontSize',14,'FontWeight','bold'); end figure; spy(A);

[B]回答:[/B]

使用noholes -option调用bwboundaries 。这消除了对象的内部边界。

换一种说法:

[B,L,N,A] = bwboundaries(BW,8,'noholes'); %# 8 is for 8-connected pixels

[url=https://stackoverflow.com/questions/4706591]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 20:32

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.