Article · Wikipedia archive · Last revised Jul 18, 2026

Pruning (morphology)

The pruning algorithm is a technique used in digital image processing based on mathematical morphology. It is used as a complement to the skeleton and thinning algorithms to remove unwanted parasitic components (spurs). In this case 'parasitic' components refer to branches of a line which are not key to the overall shape of the line and should be removed. These components can often be created by edge detection algorithms or digitization. Common uses for pruning include automatic recognition of hand-printed characters. Often inconsistency in letter writing creates unwanted spurs that need to be eliminated for better characterization.

Last revised
Jul 18, 2026
Read time
≈ 3 min
Length
605 w
Citations
2
Source

The pruning algorithm is a technique used in digital image processing based on mathematical morphology.1 It is used as a complement to the skeleton and thinning algorithms to remove unwanted parasitic components (spurs). In this case 'parasitic' components refer to branches of a line which are not key to the overall shape of the line and should be removed. These components can often be created by edge detection algorithms or digitization. Common uses for pruning include automatic recognition of hand-printed characters. Often inconsistency in letter writing creates unwanted spurs that need to be eliminated for better characterization.2

Mathematical Definition

The standard pruning algorithm will remove all branches shorter than a given number of points. If a parasitic branch is shorter than four points and we run the algorithm with n = 4 the branch will be removed. The second step ensures that the main trunks of each line are not shortened by the procedure.

Structuring Elements

B 1 = [ x 0 0 1 1 0 x 0 0 ] B 2 = [ x 1 x 0 1 0 0 0 0 ] B 3 = [ 0 0 x 0 1 1 0 0 x ] B 4 = [ 0 0 0 0 1 0 x 1 x ] {\displaystyle B_{1}={\begin{bmatrix}x&0&0\\1&1&0\\x&0&0\end{bmatrix}}B_{2}={\begin{bmatrix}x&1&x\\0&1&0\\0&0&0\end{bmatrix}}B_{3}={\begin{bmatrix}0&0&x\\0&1&1\\0&0&x\end{bmatrix}}B_{4}={\begin{bmatrix}0&0&0\\0&1&0\\x&1&x\end{bmatrix}}}

B 5 = [ 1 0 0 0 1 0 0 0 0 ] B 6 = [ 0 0 1 0 1 0 0 0 0 ] B 7 = [ 0 0 0 0 1 0 0 0 1 ] B 8 = [ 0 0 0 0 1 0 1 0 0 ] {\displaystyle B_{5}={\begin{bmatrix}1&0&0\\0&1&0\\0&0&0\end{bmatrix}}B_{6}={\begin{bmatrix}0&0&1\\0&1&0\\0&0&0\end{bmatrix}}B_{7}={\begin{bmatrix}0&0&0\\0&1&0\\0&0&1\end{bmatrix}}B_{8}={\begin{bmatrix}0&0&0\\0&1&0\\1&0&0\end{bmatrix}}}

The x in the arrays indicates a “don’t care” condition i.e. the image could have either a 1 or a 0 in the spot.

Step 1: Thinning

Apply this step a given (n) times to eliminate any branch with (n) or less pixels.

X 1 = A { B } {\displaystyle X_{1}=A\otimes \{B\}}

Step 2: Find End Points

Wherever the structuring elements are satisfied, the center of the 3x3 matrix is considered an endpoint.

X 2 = k = 1 8 ( X 1 B k ) {\displaystyle X_{2}=\bigcup _{k=1}^{8}(X_{1}\circledast B^{k})}

Step 3: Dilate End Points

Perform dilation using a 3x3 matrix (H) consisting of all 1's and only insert 1's where the original image (A) also had a 1. Perform this for each endpoint in all direction (n) times.

X 3 = ( X 2 H ) A {\displaystyle X_{3}=(X_{2}\oplus H)\cap A}

Step 4: Union of X1 & X3

Take the result from step 1 and union it with step 3 to achieve the final results.

X 4 = X 1 X 3 {\displaystyle X_{4}=X_{1}\cup X_{3}}

MATLAB Code

%% ---------------
% Pruning
% ---------------
clear; clc;

% Image read in
img = imread('Pruning.tif');

b_img_skel = bwmorph (img, 'skel', 40);
b_img_spur = bwmorph(b_img_skel, 'spur', Inf);

figure('Name', 'Pruning');
subplot(1,2,1);
imshow(b_img_skel);
title(sprintf('Image Skeleton'));
subplot(1,2,2);
imshow(b_img_spur);
title(sprintf('Skeleton Image Pruned'));

MATLAB Example

In the MATLAB example below, it takes the original image (below left) and skeletonize it 40 times then prunes the image to remove the spurs as per the MATLAB code above. As shown (below right) this removed the majority of all spurs resulting in a cleaner image.

Original Image Image Skeleton Skeleton Image Pruned
See also

See also

External links
References

References

  1. Russ, John C. (2011). The image processing handbook (6th ed.). Boca Raton: CRC Press. ISBN 978-1-4398-4045-0.
  2. Gonzalez, Rafael C.; Woods, Richard E. (2008). Digital image processing (3rd ed.). Upper Saddle River, N.J.: Prentice Hall. ISBN 978-0131687288.