clear-border

clear_border

skimage.segmentation.clear_border(labels, buffer_size=0, bgval=0, in_place=False) [source]

Clear objects connected to the label image border.

The changes will be applied directly to the input.

Parameters:

labels : (N, M) array of int

Label or binary image.

buffer_size : int, optional

The width of the border examined. By default, only objects that touch the outside of the image are removed.

bgval : float or int, optional

Cleared objects are set to this value.

in_place : bool, optional

Whether or not to manipulate the labels array in-place.

Returns:

labels : (N, M) array

Cleared binary image.

Examples

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
>>> import numpy as np
>>> from skimage.segmentation import clear_border
>>> labels = np.array([[0, 0, 0, 0, 0, 0, 0, 1, 0],
...                    [0, 0, 0, 0, 1, 0, 0, 0, 0],
...                    [1, 0, 0, 1, 0, 1, 0, 0, 0],
...                    [0, 0, 1, 1, 1, 1, 1, 0, 0],
...                    [0, 1, 1, 1, 1, 1, 1, 1, 0],
...                    [0, 0, 0, 0, 0, 0, 0, 0, 0]])
>>> clear_border(labels)
array([[0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 1, 0, 1, 0, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0]])
doc_scikit_image
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.