Effective marking of segment boundaries after image segmentation

You can mark the boundary of a binary image with the bwboundaries function from MATLAB.

What needs to be done to get the boundaries of all segments as a binary image?

I have segmented the image and want to know if there is a way to mark the borders between each adjacent segment without applying morphological operations for each segment.

I added images to illustrate what I want to do. In fact, I want to get a binary image that preserves the peak boundaries of the marker marker between all segments. That way, I can overlay them on the original image using the imoverlay function of Steve Eddin.

Random color marking of segmentation result:

enter image description here

Roughly marked pink borders between segments:

enter image description here

+4
source share
3 answers

You can find the borders of the area using a range filter that finds the range of intensity within each pixel. This takes advantage of the fact that the label matrix has only a zero range at the boundaries of the region.

im = imread('http://i.stack.imgur.com/qPiA3.png'); boundaries = rangefilt(im,ones(3)) > 0; imoverlay(label2rgb(im),boundaries,[0 0 0]); 

These edges also have a width of two pixels. In fact, I think the edges should be two pixels wide; otherwise, regions will “lose” pixels at the border unevenly.

+5
source

Since erosion and dilatation also work on non-binary images, you can write

 img = imread('http://i.stack.imgur.com/qPiA3.png'); ei = imerode(img,ones(3)); di = imdilate(img,ones(3)); boundaries = ei~=img | di~=img; 

The result is a bw image that has a border on the edge of each color area (so the line border will be two pixels wide).

enter image description here

Note that this will not return an ordered list of pixels as bwboundaries , but rather a bwboundaries boolean mask that imoverlay needs for input.

+3
source

As a round trip, I thought about using the edge function MATLAB. First, I need to apply something like the label2gray operation. label is the segmentation output (the first image provided in the question) in the code below.

 grayLabels = mat2gray(255* double(labels) ./ double(max(labels(:)))); %label2gray bw_boundaries = edge(grayLabels,0.001); 
+1
source

Source: https://habr.com/ru/post/1393458/


All Articles