This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Reduce all objects to lines in 2-D binary image or 3-D binary volume


B = bwskel(A)
B = bwskel(V)
B = bwskel(___,'MinBranchLength',N)



B = bwskel(A) reduces all objects in the 2-D binary image A to1-pixel wide curved lines, without changing the essential structure of the image. This process, called skeletonization, extracts the centerline, preserving the topology and Euler number of the objects, which correspond to white regions in the image (logical true).


B = bwskel(V) returns the skeleton of a 3-D binary volume.


B = bwskel(___,'MinBranchLength',N) specifies the minimum branch length N of the skeleton. bwskel removes (prunes) all branches shorter than the specified length. bwskel calculates the length as the number of pixels in a branch using 8-connectivity for 2-D and 26-connectivity for 3-D. The default value of 'MinBranchLength' is 0, which equates to no pruning.


collapse all

Read a 2-D grayscale image into the workspace and display it.

I = imread('threads.png');

Perform skeletonization of the image using bwskel and view the result.

out = bwskel(imbinarize(I));

Prune small spurs that appear on the skeleton and view the result.

out2 = bwskel(imbinarize(I),'MinBranchLength',10);

Load a volumetric data set into the workspace. The name of the data set is spiralVol.

load spiralVol.mat;

You can view this data set using the Volume Viewer, volumeViewer(spiralVol).

Convert the spiralVol data set to a binary format which is required by the bwskel function.

spiralVolLogical = imbinarize(spiralVol);

Skeletonize the spiral shape in the data set.

spiralVolSkel = bwskel(spiralVolLogical);

Use the Volume Viewer to view the skeletonized volume, volumeViewer(spiralVolSkel).

Input Arguments

collapse all

Input 2-D binary image, specified as a nonsparse, 2-D logical array.

Data Types: logical

Input binary volume, specified as a nonsparse, 3-D logical array.

Data Types: logical

Output Arguments

collapse all

Output image or volume, returned as a 2-D or 3-D logical array, the same size as the input image or volume.


  • While both bwskel and bwmorph can skeletonize 2-D images, you might get different results using bwmorph than when using bwskel. Because they use different algorithms, the bwskel function uses 4-connectivity with 2-D images; bwmorph uses 8-connectivity.


  • The bwskel function uses the medial axis transform.


[1] Ta-Chih Lee, Rangasami L. Kashyap and Chong-Nam Chu Building skeleton models via 3-D medial surface/axis thinning algorithms. Computer Vision, Graphics, and Image Processing, 56(6):462-478, 1994.

[2] Kerschnitzki, M, Kollmannsberger, P, Burghammer, M. et al.,Architecture of the osteocyte network correlates with bone material quality. Journal of Bone and Mineral Research, 28(8):1837-1845, 2013.

Introduced in R2018a