The pruning algorithm is a technique used in
digital image processing
Digital image processing is the use of a digital computer to process digital images through an algorithm. As a subcategory or field of digital signal processing, digital image processing has many advantages over analog image processing. It allow ...
based on
mathematical morphology
Mathematical morphology (MM) is a theory and technique for the analysis and processing of geometrical structures, based on set theory, lattice theory, topology, and random functions. MM is most commonly applied to digital images, but it can be emp ...
. It is used as a complement to the
skeleton
A skeleton is the structural frame that supports the body of an animal. There are several types of skeletons, including the exoskeleton, which is the stable outer shell of an organism, the endoskeleton, which forms the support structure inside ...
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
Edge detection includes a variety of mathematical methods that aim at identifying edges, curves in a digital image at which the image brightness changes sharply or, more formally, has discontinuities. The same problem of finding discontinuiti ...
algorithms or
digitization
DigitizationTech Target. (2011, April). Definition: digitization. ''WhatIs.com''. Retrieved December 15, 2021, from https://whatis.techtarget.com/definition/digitization is the process of converting information into a digital (i.e. computer- ...
. 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 is a term used in agricultural sciences to mean the removal of some plants, or parts of plants, to make room for the growth of others. Selective removal of parts of a plant such as branches, buds, or roots is typically known as prunin ...
Apply this step a given (n) times to eliminate any branch with (n) 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 (or dilatation) may refer to:
Physiology or medicine
* Cervical dilation, the widening of the cervix in childbirth, miscarriage etc.
* Coronary dilation, or coronary reflex
* Dilation and curettage, the opening of the cervix and surgic ...
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.
Step 4:
Union
Union commonly refers to:
* Trade union, an organization of workers
* Union (set theory), in mathematics, a fundamental operation on sets
Union may also refer to:
Arts and entertainment
Music
* Union (band), an American rock group
** ''Un ...
of X
1 & X
3
Take the result from step 1 and union it with step 3 to achieve the final results.
MATLAB
MATLAB (an abbreviation of "MATrix LABoratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementa ...
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
MATLAB (an abbreviation of "MATrix LABoratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementa ...
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.
See also
*
Morphological image processing
External links
Morphological Pruning functionin
Mathematica
Wolfram Mathematica is a software system with built-in libraries for several areas of technical computing that allow machine learning, statistics, symbolic computation, data manipulation, network analysis, time series analysis, NLP, optimi ...
Morphological Operationsin
MATLAB
MATLAB (an abbreviation of "MATrix LABoratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementa ...
References
{{DEFAULTSORT:Pruning (Morphology)
Digital geometry
Mathematical morphology