# Granulometry - MATLAB Sources

Here you will find the sources for a discrete granulometry that approximates its continuous counterpart, as presented in:

• C.L. Luengo Hendriks, G.M.P. van Kempen and L.J. van Vliet, Improving the accuracy of isotropic granulometries, Pattern Recognition Letters 28(7):865-872, May 2007.

These scripts are written for MATLAB with the DIPimage toolbox. The ZIP file below contains an M-file that implements the granulometry, as well as a couple of M-files to reproduce our experiments:

• The function GRANULOMETRY obtains a particle size distribution. It can be used in various ways, and can be configured to use the various improvements to the discrete granulometry that we have proposed. The two typical ways of calling this function are:
g0 = granulometry(img,w,1,1e4,1,1,{});
and
g1 = granulometry(img,w,8,32,1,4,{'usecenter'});
after setting e.g. w = 2.^((2:16)/2). The output g0 is the granulometry sampled at locations w using sampled Euclidean disks. g1 is computed using the optimal shift and up to 4x interpolation so that the minimal SE size is 8. Type help granulometry for more information on usage. This function is part of the DIPimage toolbox (since version 1.5.1), but has been included here for convenience (the difference between this version and the one in release 1.5.3 is the addition of the polarity parameter).
• DISK_ORIGIN is a script that measures the error made by discretizing a disk. Disks of a whole bunch of sizes are generated with their centra at different locations. We record the relative errors made at each location (P1, P2 and P errors). Note this takes quite some time to run. The second part of this script then produces an EPS file showing the error for the area of a discretized disk centered at (0,0) and at the location where this error is minimal in the mean square sense. The third part of the script produces an EPS file showing the error surface as a function of the location of the disk origin. The minimum in this surface gives the ideal origin to use when discretizing a disk of an arbitrary diameter.
• TESTIM is a script to evaluate the granulometry method for rotation invariance. It computes the granulometry with sampled disks, centered at (0,0) and at the optimal location (0.19,0.31), of a sequence of 13 images that are identical except for a rotation. The granulometry is applied with high scale sampling density on each image after 4 different interpolation factors (1,2,4 and 8). Note this takes many hours to compute; consider removing the 8x interpolation for a vastly reduced computation time. The function TESTIM_GRAPH then will generate plots that show how interpolation and shifting the disk origin improve isotropy, and how the scale sampling density is limited by the discretization error.
• CIRCLEACCURACY is a script that shows how interpolating and shifting the origin improves the resolution of the granulometry. This script compares the proposed method with other methods in the literature (implemented in the functions GRANUL_RECT, GRANUL_OCTAGON, GRANUL_PERIODIC and GRANUL_PDE). The experiment uses these various methods to compute the granulometry of a collection of disks with diameters of 6 and 10 pixels. Only the improved method is capable of distinguishing the two cohorts, and presents them at the proper location. An EPS file is generated with one size distribution computed by each of the 6 methods.