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. 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.

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

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">Thinning (morphology)">Thinning

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

Step 2: Find End Points

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

Step 3: Dilate">Dilation (morphology)">Dilate End Points

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

Step 4: Union">Union (set theory)">Union of X1 & X3

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

[MATLAB] Code


%% ---------------
% Pruning
% ---------------
clear; clc;
% Image read in
img = imread;
b_img_skel = bwmorph ;
b_img_spur = bwmorph;
figure;
subplot;
imshow;
title;
subplot;
imshow;
title;

[MATLAB] Example

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