We here propose to calculate a geodesic length factor to estimate the elongation of objects (e.g. acoustic school length), while taking into account the actual object morphology.
The geodesic length factor is a mathematical morphology metric introduced by Lantuejoul & Maisonneuve (1984), to assess "the tendency of an object to be elongated". See also Morard et al. (2013) for later developments on this topic.
We here propose a pythonic way to estimate the length factor of 2D or 3D binary images using "standard" Python libraries.
Material and Methods
2-dimension binary images
Geodesic distance calculation
skfmm.distance function does the trick. It requires:
- a binary image with the object on a background
- a boolean mask to exclude the background (==1 if the pixel is to be masked)
- a center around which to calculate the geodesic distance
One has to pass the Euclidean distance matrix within the object as a Numpy masked array to the
skfmm.distance function. The function returns a Numpy masked array containing the geodesic distances from the center of each pixel within the object.
The center has to lay within the object for the function to work. The center cannot be the object centroid (or gravity center), if dealing with non-convex objects.
We here use the "representative point" or "inner centroid" as center, to be able to process non-convex objects. The representative is a centroid that always lays within the object. It is derived from the “polygon.representative_point().wkt” attribute of a shapely “polygon” object (see this Stackoverflow thread).
Geodesic distance local maxima and geodesic radius
Geodesic distance local maxima in the object are found using the skimage
The geodesic radius of the object is defined as the maximum value of the object geodesic distance local maxima.
The length factor of an object can be calculated as (Lantuejoul, 2008):
Alpha(X)=piL²(X)/(4S(X)); Equation 1
where: • L(X) is the geodesic diameter • S(X) is the area
Beta(X)=pi*R²(X)/(S(X)); Equation 2
where: • R(X) is the geodesic radius • S(X) is the area
The calculation of the geodesic radius and Beta(X) length factor is implemented in the
geodesic_distance_skfmm function in this repository.
The function returns the geodesic radius and length factor values, as well as selected image descriptors provided by the sci-kit image package
A tutorial script displaying the function capabilities can be found in this snippet.
3-dimensions binary images
- Not clear if skfmm.distance can be used in 3 dimensions
- No method available to easily plot 3D cube
- the matplotlib
ax.voxelfunction can be used to plot voxels
2D and 3D greyscale or color images
Geodesic distances in 2D and 3D greyscale or color images can be calculated using the
geodesic_distance package. Not tested.
- Lantuejoul, C., Maisonneuve, F., 1984. Geodesic methods in quantitative image analysis. Pattern Recognition 17, 177–187. https://doi.org/10.1016/0031-3203(84)90057-8
- Morard, V., Decencière, E., Dokládal, P., 2013. Efficient Geodesic Attribute Thinnings Based on the Barycentric Diameter. J Math Imaging Vis 46, 128–142. https://doi.org/10.1007/s10851-012-0374-7