Skip to contents
library(aforoR)
library(ggplot2)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

About this tutorial

In otolith shape analysis, choosing the right mathematical descriptor is crucial for capturing the biological information relevant to your study. The aforoR package provides three main methods: Elliptic Fourier Descriptors (EFD), Wavelet Transform, and Curvature Scale Space (CSS). This vignette explains their mathematical foundations, advantages, and typical use cases.

Overview Comparison

Descriptor Domain Best For… Invariance
Elliptic Fourier (EFD) Frequency (global) General shape classification, reconstruction Translation, Rotation, Scale
Wavelets Time-Frequency (local) High-frequency details, stock separation Translation, Scale (if normalized)
Curvature Scale Space (CSS) Multi-scale Geometry Feature detection, contour irregularities Rotation, Translation, Uniform Scale
# Load a sample otolith image from the package
img_path <- system.file("extdata", "otolith.jpg", package = "aforoR")
binary_img <- preprocess_image(img_path)
contour <- extract_contour(binary_img)

# Professional visualization theme
aforo_theme <- function() {
  theme_minimal() +
    theme(
      plot.title = element_text(size = 12, face = "bold", hjust = 0.5),
      axis.title = element_text(size = 10),
      axis.text = element_text(size = 8, color = "black"),
      panel.grid.minor = element_blank(),
      panel.grid.major = element_blank(),
      axis.line = element_line(color = "black", linewidth = 0.3),
      axis.ticks = element_line(color = "black", linewidth = 0.3)
    )
}

1. Elliptic Fourier Descriptors (EFDs)

EFDs represent a closed contour as a sum of ellipses (harmonics). Each harmonic kk is defined by four coefficients (ak,bk,ck,dka_k, b_k, c_k, d_k).

  • Mathematics: Decomposes the periodic functions x(t)x(t) and y(t)y(t) into Fourier series.
  • Interpretation:
    • Low Harmonics (1-5): Capture the “global” shape, symmetry, and general elongation of the otolith (e.g., separating oval vs. rectangular shapes).
    • High Harmonics (>15): Represent fine-grained margin details, such as small serrations or irregularities that can be specific to certain stocks or environments.
  • Typical Use: Evolutionary studies, morphospace analysis, and species identification (Kuhl & Giardina, 1982).
# Example: EFD is typically calculated using the Momocs package
# The aforoR package focuses on wavelets and CSS for otolith analysis
cat("EFD captures shape through harmonics:\n")
#> EFD captures shape through harmonics:
cat("- Harmonic 1-2: Elliptical outline\n")
#> - Harmonic 1-2: Elliptical outline
cat("- Harmonic 3-5: Triangular/rectangular features\n")
#> - Harmonic 3-5: Triangular/rectangular features
cat("- Harmonic 6-10: Moderate detail\n")
#> - Harmonic 6-10: Moderate detail
cat("- Harmonic >15: Fine serrations\n")
#> - Harmonic >15: Fine serrations

2. Wavelet Transform

Wavelets analysis performs a multi-resolution decomposition of the contour signal (radius or step-length).

  • Mathematics: Uses a mother wavelet ψ(t)\psi(t) to analyze the signal at different scales jj. Scale jj corresponds to a frequency band.
  • Interpretation:
    • High Scales (7-9): Capture the main body and coarsest features of the otolith contour.
    • Mid Scales (4-6): Correspond to morphological features like lobes, indentations, and the general complexity of the protrusions.
    • Low Scales (1-3): Represent the highest frequencies, often capturing very fine margin texture or high-frequency noise.
  • Typical Use: Stock separation where differences occur in specific regions of the otolith margin (Parisi-Baradad et al., 2005).
dists <- calculate_distances(contour)
wavelets <- calculate_wavelets_analysis(dists, n_scales = 9)

# Plot Scale 5
scale_5_df <- data.frame(Index = seq_len(ncol(wavelets$polar)), Value = wavelets$polar[5, ])
ggplot(scale_5_df, aes(x = Index, y = Value)) +
  geom_line(color = "coral2") +
  labs(title = "Wavelet Scale 5 (Polar distances)", x = "Point Index", y = "Coefficient") +
  aforo_theme()


3. Curvature Scale Space (CSS)

CSS tracks the evolution of inflection points on the contour as it’s smoothed by a Gaussian kernel G(t,σ)G(t, \sigma).

  • Mathematics: Inflection points are found where the second derivative of the smoothed curve is zero: κ(t,σ)=0\kappa(t, \sigma) = 0.
  • Interpretation:
    • CSS Image Peaks: The highest peaks in the (σ,t)(\sigma, t) space represent the most stable, “deepest” concavities or convexities that survive significant smoothing.
    • Wide Distribution of Points at Low σ\sigma: Indicates a contour with many fine-grained irregularities and high-frequency “wiggliness”.
  • Typical Use: Quantifying protrusions/lobes (Mokhtarian & Mackworth, 1986).
css_res <- calculate_css(contour)
# The plot method for css object already uses a professional style if configured
plot(css_res)

Summary: Which one should I use?

  1. Use EFD for broad morphological studies where global shape is the primary driver of variation.
  2. Use Wavelets for detecting subtle population-level differences in margin complexity.
  3. Use CSS for identifying and quantifying specific geometric landmarks like lobes or indentations.

References

  • Kuhl, F.P. and Giardina, C.R. (1982). Elliptic Fourier features of a closed contour. Computer Graphics and Image Processing.
  • Mokhtarian, F. and Mackworth, A.K. (1986). Scale-based description and recognition of planar curves and two-dimensional shapes. IEEE Transactions on Pattern Analysis and Machine Intelligence.
  • Parisi-Baradad, V. et al. (2005). Otolith shape contour analysis using mathematical descriptors. Computers in Biology and Medicine.