1 Introduction

In the realm of 3D computer vision and image analysis, understanding and quantifying the geometry of 3D curves extracted from images is paramount. A primary geometric characteristic of interest is tortuosity. This term embodies the overall winding nature of a curve. While it can be defined in various ways, a simple computation often used is the ratio \(\tau = {\rm arclength}/{\rm distance}\). Despite its simplicity, this ratio encapsulates a curve’s geometric complexity, making tortuosity a fundamental descriptor for numerous applications in science and engineering [4, 13, 19, 24].

Given the intricate nature of many real-world structures, more sophisticated measures of tortuosity have been explored. Especially in the biomedical realm, where the tortuosity of blood vessels and its correlation with the severity of diseases has gained significant research interest [7, 17, 18].

Diving deeper into the concept of tortuosity, its essence emerges from the accumulated local degrees of bentness along a curve. In this context, the Slope Chain Code (SCC) stands out as a remarkable tool [5]. By encoding the sequence of 2D curve coordinates into a one-dimensional chain of exterior angles, or slope changes, the SCC captures the curve’s geometry in a compact yet detailed form. This encoding not only facilitates a granular analysis of the curve’s bending and twisting but also introduces a refined measure of tortuosity derived from the accumulation of absolute slope changes. Moreover, the SCC is invariant to several transformations, such as rotations and translations and change in size, which has cemented its utility in biomedical applications, notably in the treatment of diseases like retinopathy of prematurity (ROP) [5]. Yet, the inherent 2D limitation of SCC highlights the pressing need for a 3D adaptation, especially considering the rising significance of 3D analyses in understanding complex structures.

Transitioning to 3D is not without challenges. The additional degree of freedom in 3D accentuates the intricacies in characterizing curves, underscoring the need for robust methodologies. Recognizing the SCC’s potential, there arises a compelling need to transition its capabilities to the 3D domain, especially given the increasing importance of 3D analyses in biomedical applications. One such critical application, which stands central to this study, is the analysis of the 3D flagellar beat of human sperm. The flagellum of sperm is a tubular structure. Analyzing how the tail twists can shed light on the intricacies of sperm motility patterns and the likelihood of such a cell fertilizing an egg. This study ventures to adapt the SCC for 3D curves, aiming to capture the complexities inherent to three-dimensional structures, and demonstrates a sample biomedical application by analyzing the flagellar beat of human sperm.

1.1 Background

Curve descriptors can be broadly categorized into two types: structured and scalar. Structured descriptors, including arrays of 3D coordinates, mathematical functions like splines or Bézier curves, or chain codes offer a detailed view of a curve’s geometry. Scalar descriptors, on the other hand, are single values that provide a global, view-independent insight into curve properties. These include compactness, fractal dimension, and tortuosity among many others.

Traditionally, 3D curves are represented as arrays of 3D coordinates of vertices. While direct, this representation often becomes unwieldy, which leads to a pursuit of more synthesized descriptors that better capture the essence of the intrinsic 3D curve. The move towards parametric models like polynomials, Bézier curves, Hermite curves, and splines represents common strategies to simplify curve representation. Each model brings its unique advantages, from the intuitive control of Bézier curves suitable for design and animation to the flexibility and smoothness of splines ideal for modeling complex biological structures [27]. However, there are still major challenges to overcome like Runge’s phenomenon, in which oscillations are introduced in the representation of the curves [25]. Ongoing research has recently been dedicated to optimizing these models by applying geometric and algebraic constraints and leveraging deep learning to refine curve characteristics [2, 21, 27]. These efforts have notably improved model robustness against noise and data imperfections. However, because these models are mostly designed to represent the curve’s coordinates, they carry a significant inherent challenge for shape analysis: View-dependency. This constraint reduces their applicability in scenarios involving rotations, translations, or scaling, among other transformations; And it highlights a key contribution of the SCC, since it describes the 2D curve in a way that is structured while simultaneously invariant to such transformations, making it a significant tool in assessing structures whose orientation and scale can vary significantly [3]. This encourages the extension of the Slope Chain Code to the 3D domain.

Tortuosity can be derived from structured descriptors in a variety of ways. Most often it is measured as the ratio between the length (L) of an arc and the distance between the edges (D). \(T=L/D\), thus we will refer to this particular descriptor as “classical tortuosity". Despite being simple it currently remains a widely used descriptor in geological, and biomedical domains [1, 11, 29]. However, the simplicity of its computation comes with the cost of not properly assessing the bending degrees of the curve, which can result in  a very smooth curve and a very crooked one having  the same tortuosity if the ratio between the L and D is similar.

The shortcomings of classical tortuosity have encouraged the development of more robust tortuosity measures based on differential geometry. For a parametric 3D curve defined by \(\textbf{r}(t) = (x(t), y(t), z(t))\), where \(t\) is the parameter along the curve, the curvature \(\kappa (t)\) at any point \(t\) can be computed using the following formula:

$$\begin{aligned} \kappa (t) = \frac{\Vert \textbf{r}'(t) \times \textbf{r}''(t)\Vert }{\Vert \textbf{r}'(t)\Vert ^3} \end{aligned}$$
(1)

Here, \(\textbf{r}'(t)\) is the first derivative of the position vector with respect to \(t\), which gives the velocity vector, and \(\textbf{r}''(t)\) is the second derivative, which provides the acceleration vector. A variety of measures of tortuosity can be obtained as described in Table 1, along with recent works they have been used on.

Table 1 Summary of tortuosity measures with their respective formulas and references citing recent applications

These metrics are much more robust than classical tortuosity; however, properly describing a 3D curve should also account for its torsion. Furthermore, there is no upper bound for absolute curvature. Adapting the SCC to 3D can help address these problems.

Recently, we introduced a measure of tortuosity for 3D curves based on the 2D-SCC tortuosity [6]. It is a method developed to evaluate the complexity of 3D polygonal curves. These are 3D curves made up of vertices connecting straight-line segments of varying lengths. At each vertex, the absolute slope change is computed; however, it is important to consider that since the segments are not confined to a plane, the segments can tilt, so this tilting or torsion should also be measured for each vertex. The slope changes are scaled between 0 and 1, and the torsion between 0 and 0.5. The 3D-SCC tortuosity was defined as the sum of all absolute slope changes and torsions. It was shown that this measure of tortuosity can be useful in different applications, emphasizing its ability to discern the 3D flagellar beat pattern of human sperm in different conditions.

The present study extends the work presented in [6] by modifying the slope change and torsion equations so that each value conveys not only the degree of twisting but its relative direction. This way we effectively adapt the Slope Chain Code to three dimensions using two chains to represent an object: a slope chain (with values ranging from − 1 to 1) and a torsion chain (with values between \(-\)0.5 and 0.5). Thus the shape of the curve is preserved precisely in the encoding, and it is possible to recover the original shape. We can use this encoding to identify an object regardless of whether it is rotated, scaled, mirrored, etc. This allows us to identify local and global features of the curve, such as the tortuosity and the overall direction of the curve. Expanding the encoding in such a way allows us to investigate deeper into the shape of the flagellar centerline of sperm and how its curvature fluctuates as the sperm moves.

2 Definitions

The following definitions lay the foundation for the methodologies and analyses explored in this study. By establishing a clear understanding of these foundational concepts, we aim to ensure clarity in the subsequent sections.

Definition 1

(3D Polygonal Curve) A 3D polygonal curve is a piece-wise linear curve in a 3D space, comprised of a sequence of vertices connected by straight-line segments.

A sample 3D polygonal curve is illustrated in Fig. 1a. We refer to vertices that connect a pair of segments as inner vertices, while those connected to a single segment are referred to as outer vertices. For open curves with m segments, there will be \(n=m-1\) inner vertices. In the case of closed curves, where inherently no outer vertices exist, \(n = m\).

Definition 2

(Tangent vector) Given two consecutive vertices \(\textbf{X}_j\) and \(\textbf{X}_{j+1}\), the tangent vector \(\textbf{T}_j\) is defined as the unitary vector pointing from vertex \(\textbf{X}_j\) to vertex \(\textbf{X}_{j+1}\), mathematically represented as \(\textbf{T}_j = \frac{\textbf{X}_{j+1} - \textbf{X}_j}{\left| \left| \textbf{X}_{j+1} - \textbf{X}_j\right| \right| }\).

Definition 3

(Normal vector) The normal vector \(\textbf{N}_j\) is a unitary vector perpendicular to the segments intersecting at vertex \(j\). Mathematically, it is represented as \(\textbf{N}_j= \textbf{T}_{j-1}\times \textbf{T}_j\), where \(j>1\).

The normal vector defines a plane parallel to segments intersecting at vertex j, which is helpful for the assessment of torsion. This is known as the osculating plane.

Our encoding uses 2 chains to represent a curve: a slope chain, which is the sequence of slope changes at each vertex, and a torsion chain which represents the tilting difference.

Definition 4

(Slope Change) The slope change \(\alpha _j\) at vertex \(j\) is the normalized angle, in the range (-1,1), formed by two adjacent line-segments incident on vertex \(j\). It quantifies the local deviation from a straight path at the vertex.

Slope change, visualized in Fig. 1, encapsulates the local bending of the curve, with 0 indicating the two segments follow a linear path, and 1 signifying that the segments have opposite directions. Fig 1b shows the range of slope changes.

Definition 5

(Torsion) Torsion \(\beta _j\) at vertex \(j\) is defined as the normalized angle, within [\(-\)0.5, 0.5], representing the amount a segment \(s_i\) needs to roll along segment \(s_j\) to be co-planar with \(s_{j+1}\). Vertex \(i\) is the most recent non-co-linear vertex before \(j\).

Torsion, essentially, gauges the tilt of a curve segment sequence. It requires at least three segments for computation and is thus absent for the first inner vertex in open curves. For a curve, the number of slope changes and torsions are denoted as \(n_\alpha\) and \(n_\beta\) respectively, with \(n_\alpha = n\) and \(n_\beta = n\) for closed curves, and \(n_\beta = n - 1\) for open ones. Further details on torsion computation are elaborated in Sect. 2.2.

2.1 Computing slope changes in a 3D polygonal curve

We assume that the vertices of a 3D polygonal curve have already been extracted from the source. To compute the slope chain of a 3D curve we must select an initial vertex (indicated by a red sphere in Fig. 1a) and travel along the sequence of vertices. We aim to adapt the SCC's ability of describing 2D curves based on their  local curvature and relative direction to 3D. For this reason, we modified the expression given for the slope changes in [6], including a sign that switches whenever a sequence of segments is concave. Mathematically, the slope change at vertex \(\textbf{X}_j\) is denoted as

$$\begin{aligned} \alpha _j = sign_{\alpha _j}\arccos \left( \frac{\textbf{T}_j \cdot \textbf{T}_{j+1}}{ || \textbf{T}_{j} ||\, || \textbf{T}_{j+1} ||} \right) / \pi \end{aligned}$$
(2)

for \(j=2,3,...,m-1\). If the curve is closed, the slope change between segment m and segment 1 can at the closing vertex \(\textbf{X}_m\) can be computed as

$$\begin{aligned} \alpha _m = sign_{\alpha _m}\arccos \left( \frac{\textbf{T}_m \cdot \textbf{T}_{1}}{ || \textbf{T}_{m} ||\, || \textbf{T}_{1} ||} \right) / \pi . \end{aligned}$$

The sign of the first slope change (i.e. \(sign_{\alpha _1}\)) can be set arbitrarily. In this work, we will always consider it 1. For the following angles, \(j=2,3,...,m-1\)

$$\begin{aligned} sign_{\alpha _{j}}= \left\{ \begin{array}{ll} sign_{\alpha _{j-1}} &{} \hbox {if} \quad (\textbf{T}_i\cdot \textbf{v}_i)(\textbf{T}_{j+1}\cdot \textbf{v}_i) < 0, \\[1ex] (-1)sign_{\alpha _{j-1}} &{} \hbox {otherwise}. \end{array}\right. \end{aligned}$$

where i is the index of the last vertex connecting a pair of segments that is not colinear, \(\textbf{v}_i=\textbf{N}_i\times \textbf{T}_i\). \(\textbf{T}_i\) indicates the local forward direction, serving as a provisional x-axis, and \(\textbf{v}_i\) serves as the y-axis. If \(\textbf{T}_{i-1}\) and \(\textbf{T}_j\) move towards opposite sides of the “x" plane the sign remains the same, since the curve is curling more, whereas if they end up on the same side of the “x" axis the sign is negative. Thus, the arccosine measures the absolute slope change and the sign remains the same if the sequence rotates in the same direction, forming a C-shape, and the sign changes if the sequence of segments forms an S-shape. If the curve is closed the sign for the last vertex can be computed replacing \(\textbf{T}_{j+1}\) with \(\textbf{T}_1\) in the sign equation.

Figure 1c shows the computation of the first slope change. Figure 1d illustrates all computed slope changes of the curve, with subsequent slope changes computed considering the next pair of 3D straight-line segments. Notice that the segments of the curve do not need to be of the same length. The step-by-step computation process for determining slope changes along a 3D curve, including the handling of closed curves and local S-shaped configurations, is formally outlined in the algorithm provided in Algorithm 1.

Fig. 1
figure 1

Computation of the slope change: a Sample 3D polygonal curve, b slope change range (\(-1,1\)), c computation of the slope first slope change, and d computation of all the slope changes of the curve. The slope chain of this curve is: [ 0.5 0.5 \(-\)0.25 0.5 0.5 \(-\)0.5 \(-\)0.3 \(-\)0.2 \(-\)0.4 ]

Algorithm 1
figure a

Compute slope changes for 3D curve

2.2 Calculating torsions in a 3D polygonal curve

Torsions in a 3D polygonal curve are derived by determining the angle between planes containing segments, connected at vertices \(i\) and \(j\). Again we modified the equation from [6] to allow positive or negative signs depending on whether the plane tilts upwards or downwards from the plane containing the previous segments, using the right-hand rule as a frame of reference. The torsion at vertex j is expressed as:

$$\begin{aligned} \beta _j = \arcsin \left( \frac{\textbf{T}_i\cdot (\textbf{N}_{i} \times \textbf{N}_{j})}{||\textbf{N}_{i}||\, || \textbf{N}_{j}||}\right) /\pi , \end{aligned}$$
(3)

where vertex i and j are connected by a straight path of one or more segments.

Figure 2 illustrates the osculating planes used to compute the torsion of the 3D polygonal curve displayed in Fig 1a. As the first vertex of an open polygonal curve lacks torsion, the computation starts from the second vertex, proceeding sequentially to subsequent vertices. Thus torsion chain of the curve in Fig. 2 is: [ 0. 0. \(-\)0.5 0.2 0.25 0.1 \(-\)0.3 -0. ].

Fig. 2
figure 2

Osculating planes. The torsion is the tilting angle between these planes

When slope changes are zero, the algorithm to compute torsions becomes slightly intricate since a tangent plane could assume any orientation, resulting in a lost torsion reference frame. Thus, the algorithm utilizes Remark 1 to retain the last corner vertex \(i\) as a reference for the torsion of vertex \(j\). Additionally, if the initial vertex of an open curve is zero, an initial plane of reference for torsion cannot be immediately established due to the vectors being co-linear. In this scenario, we set \(\beta _1 = 0\). This is repeated as \(\beta _{j+1} = 0\) for every vertex \(j\) until \(\alpha _j \ne 0\) is found, ultimately allowing the establishment of the tangent plane. The torsion at vertex \(j+1\) will be determined between the segments at vertex \(j\) and \(j+1\). Algorithm 2 outlines the process of obtaining the torsion chain.

Remark 1

For any vertex \(j = 1, \ldots , n\); if \(\alpha _j = 0\), then \(\beta _j = 0\).

If the curve is closed two additional torsions must be computed: The torsion at the first inner vertex, and the torsion at the last inner vertex. The first torsion \(\beta _1\) in this case is the angle between the plane containing the last two non-colinear segments and the first 2 segments, and the last torsion \(\beta _n\) is given by segments i, n and 1, where both planes contain segment n.

Algorithm 2
figure b

Compute torsion for 3D polygonal curve

3 Properties

In this chapter, we comprehensively explore the properties of the 3D-SCC, which are crucial for pattern recognition tasks. Among the properties we will discuss are uniqueness, invariance to translation, rotation, and scaling, as well as other essential characteristics that contribute to robust pattern recognition algorithms. By elucidating these properties, we aim to provide a foundational understanding that empowers researchers and practitioners in fields such as computer vision, biomedical imaging, and beyond.

First, our encoding methodology significantly expands on our previous work [6] by ensuring each curve has a unique encoding. This unique representation relies on one key condition: when comparing two curves, the corresponding segments in each curve should match in length. By incorporating directional information in the slope and torsion calculations, our method accurately captures the distinct geometric characteristics of each curve. This unique encoding is crucial for distinguishing between different curves, enhancing the precision and usefulness of our method in fields like computer vision and biomedical imaging, where accurate curve characterization is vital.

Furthermore, the 3D encoding exhibits invariance under translations, rotations, and uniform scaling transformations. This stems from the relative nature of the slope changes and torsions computed between contiguous straight-line segments. Figure 3 illustrates these invariances through various transformations applied to the 3D polygonal curve depicted in Fig. 1a, all of which retain the same encoding.

Fig. 3
figure 3

Rotated, translated, and scaled polygonal curve. All of them have the same slope and torsion chains

More complex transformations can invert the signs in the torsion chains. For example, the symmetry of a mirror transformation leaves the slope chain unaltered, while the torsion chain’s signs invert. This occurs because the first slope change has a fixed sign (positive in our work) but the torsion must invert to comply with the right-hand rule. This property is illustrated in Fig. 4.

Fig. 4
figure 4

Mirrored curve. Both curves have the same slope chain and opposite-signed torsions

If a curve is traveled in reverse order, its torsion chain will be the same, but in reverse order and with inverted signs. The slope chain will also reverse and the signs will be inverted if the first and last signs of the original chain do not match. Furthermore, in a closed curve any vertex can be chosen as the starting vertex and the encoding will be the same, but shifted and possibly with inverted signs. Figure 5a, b elucidate this invariance for an open curve, while Fig. 5c, d extend this illustration to a closed curve.

Fig. 5
figure 5

Polygonal curves with different starting points. a When the 3D polygonal curve shown in Fig. 1a is traveled in reverse, its slope and torsion chains are reversed and their signs switch. b closed curve with different starting points

Finally, it is important to point out that the 3D-SCC was designed so that if a curve is planar, i.e. all of its torsions are 0, the slope chain will be equal to the 2D SCC (or its mirror image if the first slope change is negative (clockwise)).

3.1 Accumulated angles

A helpful feature of the slope chain code is the ability to obtain complex properties of a curve by simply adding their values. In 3D the sum of slope changes and torsions, signed and absolute can provide helpful insights about the structure of a curve that contribute to their analysis and classification.

Definition 6

(Accumulated slope change) The accumulated slope change of a 3D polygonal curve is the sum of all its slope changes and it is denoted as:

$$\begin{aligned} \alpha _{a}=\Sigma _1^n \alpha _j , \end{aligned}$$
(4)

where n is the number of inner vertices of the curve (\(n=m-1\) for closed curves and \(n=m\) for open ones).

Definition 7

(Accumulated absolute slope change) The accumulated absolute slope change of a 3D polygonal curve is the sum of the absolute values of all its slope changes and it is denoted as:

$$\begin{aligned} \alpha _{aa}=\Sigma _1^n |\alpha _j| \end{aligned}$$
(5)

The accumulated absolute slope offers critical insights into the geometric nature of 3D curves. Notably, a 3D polygonal curve is a straight line if and only if its accumulated absolute slope change equals 0. Furthermore, the accumulated absolute slope change of any closed curve is at least 2, since it is the minimum total rotation required to return to the starting point.

Remark 2

The accumulated absolute slope change of any closed curve is at least 2.

Definition 8

(Slope Direction Factor (SDF)) The Slope Direction Factor is given by

$$\begin{aligned} SDF=\frac{\alpha _{a}}{\alpha _{aa}}. \end{aligned}$$
(6)

It is a descriptor that is 1 if all slope changes are positive, -1 if all slope changes are negative, and 0 if they balance out. The accumulated slope change of the polygonal curve in Fig. 1a is \(0.5 + 0.5 -0.25 + 0.5 + 0.5 -0.5 -0.3 -0.2 -0.4=0.35\). The accumulated absolute slope change of the polygonal curve in Fig. 1a is 3.65. Thus its SDF is 0.35/3.65.

Definition 9

(Accumulated torsion) The accumulated torsion of a 3D polygonal curve is the sum of its torsions, i.e.:

$$\begin{aligned} \beta _{a}=\Sigma _1^n \beta _j \end{aligned}$$
(7)

Definition 10

(Accumulated absolute torsion) The accumulated absolute torsion of a 3D polygonal curve is the sum of its torsions, i.e.:

$$\begin{aligned} \beta _{aa}=\Sigma _1^n |\beta _j| \end{aligned}$$
(8)

The accumulated torsion of the curve in Fig. 2a is \(-0.5 + 0.2 + 0.25 0.1 -0.3=-.25\). Its accumulated torsion is 1.35.

Remark 3

A polygonal curve is planar if and only if its accumulated absolute torsion is 0.

4 3D slope chain code tortuosity

Definition 11

(3D-SCC Tortuosity) The 3D-SCC tortuosity, denoted by \(\tau\), of a polygonal curve is computed as the sum of the absolute slope changes and absolute torsions occurring between adjacent line segments, mathematically represented as:

$$\begin{aligned} \tau = \alpha _{aa} + \beta _{aa} \end{aligned}$$
(9)

This derives from the definition given in our previous work [6], but is adapted to consider the absolute value, which would have been redundant in that work since all angles were positive because they were not directional. In Fig. 1a, the computed slope and torsion values aggregate to \(\tau = 3.65 + 1.35 = 5\).

4.1 Invariance

Due to the properties of the 3D encoding, the 3D SCC tortuosity is invariant under rotation, translation, scale, mirror imaging, and starting point, since the absolute values do not change.

4.2 Extrema of 3D tortuosity

From this section on, we address 3D polygonal curves with equal-sized segments exclusively. A 3D polygonal curve manifests the minimum tortuosity value of \(\tau = 0\) when all its slope changes are null. Conversely, the maximum value of tortuosity is reached when all slope changes approximate \(\pm 1\) and every torsion angle measure \(\pm 0.5\). This yields a maximum accumulated slope of \(n\) (number of inner vertices), and a maximum accumulated torsion of \(\frac{n-1}{2}\) if the curve is open or \(\frac{n}{2}\) if it is closed. Thus the upper bound for the tortuosity \(\tau _{max}\) of a curve with n inner vertices is \(n+\frac{n-1}{2}=\frac{3n-1}{2}\) if it is open and \(n+\frac{n}{2}=\frac{3n-1}{2}\) for closed curves. Therefore, the tortuosity of any given open curve is bounded within the interval \([0, \tau _{max})\)

4.3 Normalized 3D tortuosity

The preceding section delineates how the maximum tortuosity value escalates with the number of vertices within the polygonal curve. To surmount this, we propose a normalized tortuosity measure that facilitates a standardized comparison across curves with disparate vertex counts. This normalization is not only conducive to comparative analysis but also aligns well with the prerequisites of numerous regression and classification models in which bounded descriptor values are preferred.

Definition 12

(Normalized Tortuosity) The Normalized Tortuosity, denoted \(\tau _N\), is derived by scaling the raw tortuosity \(\tau\) by the maximum possible tortuosity given the number of vertices, expressed as:

$$\begin{aligned} \tau _N = \frac{\tau }{\tau _{max}}. \end{aligned}$$
(10)

This normalization ensures that the tortuosity measure lies within the continuous range \([0, 1)\). For instance, the left curve in Fig. 6 exhibits the minimum normalized tortuosity value of zero, while the right curve approaches the maximum value of one.

Fig. 6
figure 6

3D polygonal curves exhibiting minimal and maximal tortuosity

The normalized tortuosity of the curve described in Fig. 1a is \(5/(9+4)=0.38\)

Overall this encoding can accurately depict the shape of 3D curves directly and through the computation of descriptors such as the 3D-SCC tortuosity and normalized tortuosity, stand out as robust descriptors of the geometric essence of 3D curves. The encoding is impervious to alterations in translation, size, and other extrinsic factors. Their utility extends to ranking curves based on tortuosity, aiding in shape comparison, and classification. Moreover, it promises significant advancements in detecting and analyzing the geometry of 3D tubular structures and curves prevalent in veins, respiratory airways, arteries, and architectural infrastructures, among others.

5 Results

5.1 Analysis of knots using 3D-SCC descriptors

The study of closed curves -also known as knots- finds diverse applications in topology, graph theory, fluid mechanics, and chemistry. In these domains, the ability to quantitatively describe and analyze curve shapes—a process often reliant on visual interpretation—is invaluable. Descriptors extracted through the 3D-SCC can transform these qualitative observations into quantitative data, facilitating the classification and ranking of various patterns.

Figure 7 presents several closed curves comprised by different numbers of vertices n, each exhibiting distinct characteristics. Accompanying Table 2 quantifies their properties, including accumulated slope, accumulated torsion, and overall tortuosity. Figure 7a displays a simple curve, characterized by its smoothness, which registers the lowest tortuosity among the samples. Its simplicity is reflected in its minimal tortuosity. Figure 7b is a tree-foil knot; it is curlier, with a slightly higher absolute slope change contributing to a higher tortuosity. Finally, Fig. 7c has much more significant twists, giving the highest accumulated slope changes and torsions. The curves were initially sampled with 100 vertices, and upon increasing the resolution to 1000 the accumulated slope change and torsion maintained several digits of precision hinting that 3D-SCC tortuosity is robust against changes in resolution as long as the data isn’t too coarse.

Fig. 7
figure 7

Sample closed 3D polygonal curves illustrating varying degrees of tortuosity

Table 2 Quantitative analysis of the 3D polygonal curves in Fig. 7

Notice that the first curve has a an accumulated absolute slope change of 3.21, in contrast with the curves that cross themselves. The accumulated absolute slope change is an important descriptor in the analysis of knot complexity. A trivial knot, or an unknot, is a simple closed curve which does not cross itself, such as the one observed in Fig 7a. A non-trivial knot, in contrast, is a closed curve that twists around itself in a way that it cannot be untangled into a circle without cutting it, such as the one in Fig 7b. Identifying whether a closed curve is knotted or unknotted can be an extremely challenging task visually or mathematically if the curve is convoluted. The Fary-Milnor theorem provides a helpful criterion to determine that a knot is trivial by stating that any closed curve with a crossing number higher than 0 must have an accumulated absolute curvature angle of at least \(4\pi\) [22]. We can adapt this theorem for any closed curve encoded through the 3D-SCC as follows:

Theorem 1

(3D SCC Fary-Milnor Theorem) Any non-trivial knot’s accumulated absolute slope change is at least 4.

Recalling Remark 2, a full loop contributes to accumulated absolute slope change by at least 2, since a lower accumulated slope change is not enough to close a loop. Theorem 1 can be thought of as a result of the fact that a nontrivial knot requires at least 2 full loops: A “main" loop and a secondary one around it which ties the knot, so the curvature must be at least \(2+2=4\). Therefore, if any closed curve that has an accumulated absolute slope change lower than 4 is an unknot.

5.2 Analysis of the 3D flagellar beat of human sperm

To demonstrate the potential real-world applications of this 3D encoding, we highlight its utility in identifying 3D beating patterns in the tail of human sperm. In their pursuit of the egg, human spermatozoa use a complex, three-dimensional beat of their flagellum to navigate through the reproductive tract. Identifying flagellar beat patterns is crucial to understanding whether a sperm can fertilize the egg, however, their rapid, intricate, and three-dimensional nature contributes to obscure the true nature of these patterns. Furthermore, as spermatozoa navigate through their medium, they translate and rotate along their movement axis. Typically, since the flagellum is a complex 3D curve, it requires an analysis through view-dependent, structured representations. To address this, mathematical modeling techniques are employed to fit a plane that moves and rolls with the cell, serving as a dynamic frame of reference. However, the 3D-SCC can be employed directly on freely swimming cells, eliminating the need for such constraints. Therefore, the use of rotationally invariant descriptors becomes essential for an accurate evaluation of the flagellar beat. We believe that 3D-SCC can provide valuable insight into identifying the flagellar beating patterns of fertile human sperm.

The 3D flagellar beat of 90 freely swimming human sperm was analyzed. During each experimental session, an individual, freely-swimming spermatozoon was imaged for  3 s utilizing an experimental apparatus consisting of an inverted microscope equipped with a piezoelectric device [9, 15]. This device induced vibrations in the objective along the z-axis at a frequency of 90 Hz, spanning a vertical range of 20 \(\mu\)m, while a high-speed camera simultaneously captured images at a rate of 8000 frames per second. Consequently, images obtained at various heights were systematically aligned to reconstruct the 3D+time recorded volume. The flagellum’s centerline was segmented from each 3D frame using a semi-automated algorithm designed to find a path, connecting the sperm head and distal point of the flagellum via approximately 400 3D linear segments of equal lengths. The flagellum was smoothed with a least squares B-spline to eliminate high-frequency noise in the centerline coordinates. This approach generated a 3D open polygonal curve. Further details on the data acquisition and segmentation methodologies were discussed in [15].

5.2.1 3D slope chain analysis

Analyzing the 3D slope chains of the flagellum can provide interesting information on the flagellar beat since they allow us to quantitatively monitor how the curvature travels along the flagellum while the sperm swims. The slope chain represents how much the flagellum bends in each of its regions, and in which relative direction. Thus Fig. 8a shows the flagellum of a sperm with a slow flagellar beat over 12/90 s. The color represents the value of the slope chain in that region. Thus, we can observe that regions with a significant bend correspond with high values in the slope chain (red regions). The flagellum of this curve is very smooth with long quasi-linear regions (green) and a main curvature region (red) traveling slowly from the neck towards its endpoint with the whip-like motion of the flagellum. A spermatozoon with a more tortuous flagellar beat is shown in Fig. 8b during a span of 6/90 s. In this case, the flagellum has multiple critical points (red regions), contributing to its high tortuosity. Notice that the slope changes are always positive (no regions of the flagellum are tainted blue). This occurs because the Slope Direction Factor is high for the recorded cells, averaging 0.88. This indicates that the flagellum is a helix-like structure.

Fig. 8
figure 8

Slope changes of the flagellar beat of a a human sperm elapsing 12/90 s with low tortuosity and b Slope changes of the flagellar beat of a highly tortuous human spermatozoon elapsing 6/90 s. The color represents the slope changes

5.2.2 3D-SCC flagellar tortuosity

Upon obtaining the slope and torsion chains of the flagellum at each time frame of the 90 analyzed cells, we computed their 3D-SCC tortuosity. The average tortuosity of each experiment ranged from 3.4 to 5.2 (normalized tortuosity between 0.033 and 0.050). Figure 9 illustrates the flagellar beat of 3 sample sperm over 0.25 s, with increasing tortuosity values. Figure 9a displays a spermatozoon with low flagellum tortuosity (Average \(\tau = 3.6\)). Figure 9b shows a sperm with medium tortuosity (Average \(\tau =4.1\)). Finally, a cell with high flagellar tortuosity (\(\tau =5.1\)) is shown in Fig. 9c. As the tortuosity increases, the flagella tend to be less smooth and more crooked.

Fig. 9
figure 9

3D flagellar beat over 0.25 s for a a sperm with low flagellar tortuosity, b a sperm with medium flagellar tortuosity, and c a sperm with high flagellar tortuosity

5.2.3 3D-SCC tortuosity of the sperm head trajectory

Analyzing the shape of 3D sperm head trajectories is another crucial aspect in understanding sperm motility [10]. Our method, employing 3D-SCC, can contribute further by encoding these trajectories and computing their 3D-SCC tortuosity, offering enhanced insights into sperm dynamics. Figure 10a shows the 3D trajectory of a sample sperm with low tortuosity (\(\alpha _{aa}=10.09\), \(\beta _{aa}=7.10\), yielding a tortuosity of 17.19, or normalized tortuosity of 0.063). It has very smooth and wide movement as the sperm moves in a linear path. Wide lateral movement is known to be an important feature in the motility of fertile cells [20]. In contrast, Fig. 10b shows the 3D path of a sperm with high 3D-SCC tortuosity, which has very short and sudden motions as it swims, with \(\alpha _{aa}=28.24\), \(\beta _{aa}=20.36\), \(\tau =48.6\), or normalized tortuosity of 0.180.

Fig. 10
figure 10

3D trajectories of sperm with a low 3D-SCC tortuosity and b high 3D-SCC tortuosity for 2 s. The red dot indicates the start of the trajectory

5.3 Comparison with established methods

This section evaluates the newly developed 3D Slope Chain Code (3D-SCC) against traditional curve descriptors that are commonly used in the analysis of complex 3D structures. We focus on crucial aspects such as the ability to assess shape similarity directly, robustness to geometric transformations, and enhanced sensitivity to geometric features.

5.3.1 Shape recognition

Traditional structured descriptors, such as arrays of coordinates or polynomial approximations, effectively capture local and global curve features but are inherently dependent on the curve’s orientation, size, and position. To use these descriptors for comparing shapes, significant processing is required to normalize these aspects, which can be computationally intensive and error-prone.

In contrast, the 3D Slope Chain Code (3D-SCC) is designed to be independent of the curve’s view. This unique attribute allows it to assess the similarity of shapes directly, without the need for the normalization processes such as translation, rotation, and scaling that other methods require. This direct comparison capability is especially advantageous in fields where dynamic changes in viewpoint occur, such as in biomedical imaging and real-time object recognition systems. For example, freely swimming sperm translate and rotate as they swim. This movement can complicate identifying flagellar beat shapes. Figure 11a shows the flagellum of a spermatozoon and Fig. 11b shows the same flagellum, but rotated \(-30 ^\circ\) around the y-axis and \(25^\circ\) around the z-axis. Table 3 demonstrates how the 3D-SCC maintains consistency after the rotation, whereas other descriptors like arrays of coordinates and cubic splines exhibit significant changes when subjected to rotation, complicating the recognition of flagellar patterns.

Fig. 11
figure 11

Comparison of a the original and b rotated flagellum

Table 3 Comparison of structured descriptors of the flagellum before and after rotation displayed in Fig. 11

The invariance of the 3D-SCC to geometric transformations provides a significant advantage in analyzing flagellar motion. While previous methods often relied on applying mathematical transformations to fit a dynamic frame of reference that moves and rolls with the cell [12, 14], the 3D-SCC simplifies this process. This simplification not only reduces the computational burden but also minimizes the risk of introducing errors during transformation.

By directly comparing intrinsic geometric properties, the 3D-SCC offers a more accurate and efficient analysis. This capability simplifies the analytical workflow and enhances the reliability of the results. The ability to bypass normalization steps facilitates faster and more accurate assessments of shape similarity, making the 3D-SCC particularly valuable for applications requiring rapid and robust shape analysis.

In conclusion, the 3D-SCC’s intrinsic ability to directly compare shapes without pre-processing provides a substantial advantage over traditional methods that require extensive and often cumbersome normalization processes. This makes it especially suited for real-time applications and dynamic environments, such as those encountered in biomedical imaging and object recognition systems.

5.3.2 Comparison of tortuosity measures

Tortuosity measures, unlike traditional structured descriptors, are predominantly view-independent and aim to capture the curve’s essence in a single value. A key contribution of 3D-SCC tortuosity relies in it’s sensitivity to the curve’s geometry, comprising all its slope changes and torsions. For instance, classical tortuosity calculates the ratio of the chord-length to the distance between the edges [23], so if two curves of equal length start and end at the same distance, as shown in Fig. 12 they will yield the same tortuosity value. In contrast, the 3D-SCC tortuosity correctly ranks the spiral- which is visibly more twisted than the parabolic arc- curve as significantly more tortuous, with values of 5.53 and 0.60 respectively, showing that it can provide a deeper insight into the curve’s shape.

Fig. 12
figure 12

Visualization of two contrasting curves illustrating the application of the 3D-SCC tortuosity calculation. The green curve represents a parabolic arch, and the red curve depicts a spiral structure. Despite both curves having classical tortuosity of 1.27, the 3D-SCC method effectively differentiates their complexity, assigning higher tortuosity values to the visibly more twisted spiral, with computed tortuosities of 5.53 and 0.60, respectively

Curvature-based measurements of tortuosity are much more robust than classical tortuosity since they quantify how much each pair of segments deviate from a straight 3D path. This aligns with the accumulated absolute slope change, however, to truly quantify the degree of bending of a curve, out of plane motion should also be considered, so it is important to include torsion. Figure 13 shows the flagella of two different human sperm, and Table 4 shows their tortuosity values calculated by the methods described in Table 1 and 3D-SCC tortuosity. Both flagella have the same length, comprised by 40 straight line segments of a length of 1 \(\mu m\) and they have the same distance between the head and the end of the flagellum, so they yield the same classical tortuosity, despite representing very different curves. Curvature-based metrics are not sensitive enough to distinguish the shapes either, largely due to them neglecting torsion. In contrast, 3D-SCC tortuosity is a descriptor that accurately captures both flagella as very different curves.

Fig. 13
figure 13

Two flagella with similar values for traditional tortuosity measures but different 3D-SCC values

Table 4 Calculated tortuosity values for the two flagella depicted in Fig. 13, using the measures detailed in Table 1, including 3D-SCC tortuosity

Classical tortuosity has been widely used in the analysis of sperm flagellar beat. Curvature-based measures are theoretically available and more robust, yet their application is less common in the literature. Furthermore, the comparative analysis demonstrated in Table 4 clearly shows the advantages of using the 3D-SCC tortuosity measure. This descriptor not only provides a more detailed and accurate representation of the flagellar beat’s complexity but also captures essential aspects such as torsion, which are often overlooked by classical and simpler curvature-based measures. Therefore, adopting 3D-SCC tortuosity could significantly enhance the analysis and understanding of sperm flagellar dynamics in 3D contexts.

Thus, the 3D-SCC tortuosity measure can be helpful in improving flagellar tortuosity analyses that used more ambiguous descriptors, such as: [16, 28].

6 Conclusion

We developed an encoding for 3D curves based on the Slope Chain Code which uses two chains in parallel to represent them: a slope chain and a torsion chain. It is invariant under changes in size, rotation, and translation, and robust to mirror imaging and starting point. It allows the extraction of features such as tortuosity, accumulated angles, and direction factors. We showed the potential of this encoding in the analysis of knots and closed curves. Furthermore, we exemplified the biomedical application of this encoding showing its potential in the analysis of the 3D flagellar center-line human sperm. The variability in 3D-SCC tortuosity highlighted the diverse range of flagellar beat patterns in human sperm. The high Slope Direction Factor indicated a predominantly helix-like flagellar motion among the sperm. We believe these could be useful features in medical systems to identify fertile cells since they are statistically significant, in contrast to their 2D counterparts. While we demonstrated significant findings in the context of reproductive biology, the potential applications of our 3D-SCC method extend into other areas of computer vision and 3D curve analysis. This versatility opens up avenues for future research in medical imaging, robotics, and more. Future work could focus on refining the encoding method to enhance its accuracy and exploring its application in other complex 3D structures beyond biological systems.