|
Hi Bard,
I have written a code which I haven't submitted to the FEX so far, which does what you need. Just send me a message via the contact formula with your email address and I'll send it to you.
Cheers,
W.
"Bard R." wrote in message <j4nj00$s0j$1@newscl01ah.mathworks.com>...
> Hi,
> I have a labeled image L which is produced using the watershed function.
> Now I want to plot a boundary around each region, but I want the boundaries to be placed on the watershed line (center of the background pixel) rather than along the edge of each region.
> As you can see from the example below bwboundaries does not give me the result I want. I thought I could do this by dilating each region individually such as, but that doesnt work well either. I guess I may have to trace the background pixels directly in some way rather than the boundary of the region itself. Any suggestions would be much appreciated.
>
> %Example code:
> Z = peaks(50);
> L = watershed(Z,4);
> figure, imagesc(L)
> title('Inner boundaries')
> %Get inner boundaries...
> B1 = bwboundaries(L,4,'noholes');
> %...and plot them
> hold on
> for k = 1:length(B1)
> boundary = B1{k};
> plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
> end
> %
> %I thought this would do the trick...
> %
> figure, imagesc(L)
> title('Better, but not quite')
> hold on
> for i = 1:max(L(:))
> boundary = bwboundaries(imdilate(L==i,[0 1 1;1 1 1;0 1 0]),4,'noholes');
> boundary = boundary{1};
> plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 2)
> end
> %
> %But as you see that doesn't work well in the corners.
> %
|