开发者

bwboundaries -, in MATLAB-, preprocessing

开发者 https://www.devze.com 2023-02-04 19:38 出处:网络
I just want to trace boundaries in my gray image. I got problem by getting a region boundary two times. How can I get only one boundary and in center of edge pixel.

I just want to trace boundaries in my gray image. I got problem by getting a region boundary two times. How can I get only one boundary and in center of edge pixel. In the following example I got two regions 4开发者_Go百科, 30. But I need only (4). Which image pre- processing is required to get that.

example: please see region 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);


Call bwboundaries with the noholes-option. This removes inner boundaries of objects.

In other words:

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

精彩评论

暂无评论...
验证码 换一张
取 消