Overview

2D shape features quantify the geometric properties of a 2D object extracted from binary masks. These features provide valuable information for shape analysis in medical imaging, characterizing size, compactness, and morphological properties of regions of interest.

Input Parameters

  • mask_array: A 2D binary array (BitArray) representing the shape region of interest
  • spacing: A vector of Float32 values indicating the pixel spacing in each dimension
  • verbose: A Boolean flag to enable progress messages during computation

Extracted Features

The function get_shape2d_features returns a comprehensive dictionary containing the following geometric features:

Perimeter

The perimeter of the shape, calculated by tracing the boundary pixels and scaling with pixel spacing. This measure represents the total length of the object's boundary.

P = Σ edge_lengths (scaled by spacing)

Mesh Surface

The area of the 2D shape estimated using a mesh of the contour points. This provides a precise surface area calculation based on the object's boundary geometry.

A_mesh = area from contour triangulation

Maximum 2D Diameter

The largest distance between any two points on the contour of the shape. This feature represents the maximum extent of the object and is useful for size characterization.

D_max = max(||p_i - p_j||) for all contour points

Pixel Surface

The area computed as the number of pixels in the mask multiplied by the pixel spacing in both dimensions. This represents the total area covered by the object.

A_pixel = N_pixels × spacing_x × spacing_y

Perimeter to Surface Ratio

Ratio of perimeter to surface area. This normalized measure describes the shape's complexity independent of scale.

PSR = P / A

Sphericity

A measure of how circular the shape is. Values closer to 1 indicate a more circular shape, while values closer to 0 indicate irregular shapes.

S = (2 × √(π × A)) / P

For a perfect circle, S = 1

Major Axis Length

The length of the major axis of the shape, calculated from the largest eigenvalue of the covariance matrix of pixel coordinates. Represents the primary direction and extent of the shape.

L_major = 4 × √λ_max

where λ_max is the largest eigenvalue of the covariance matrix

Minor Axis Length

The length of the minor axis of the shape, calculated from the smallest eigenvalue of the covariance matrix. Represents the secondary direction and extent perpendicular to the major axis.

L_minor = 4 × √λ_min

where λ_min is the smallest eigenvalue of the covariance matrix

Elongation

Ratio of minor to major axis lengths. This describes how elongated the shape is, with values closer to 1 indicating a more circular shape and values closer to 0 indicating a highly elongated shape.

E = √(λ_min / λ_max) = L_minor / L_major

Computational Methods

The 2D shape features are computed using sophisticated image analysis techniques:

  • Marching Squares Algorithm: The perimeter, surface, and diameter are computed using a marching squares approach with vertex interpolation for sub-pixel accuracy.
  • Covariance Matrix Analysis: The eigenvalues and eigenvectors of the covariance matrix of pixel coordinates are computed to extract major/minor axes and elongation metrics
  • Direct Pixel Counting: Pixel surface calculation employs direct counting of mask pixels, appropriately scaled by the provided spacing information

Notation Legend

  • P = Perimeter
  • A = Area/Surface
  • D_max = Maximum diameter
  • N_pixels = Number of pixels in mask
  • λ_max, λ_min = Largest and smallest eigenvalues
  • L_major, L_minor = Major and minor axis lengths
  • ||·|| = Euclidean distance

Usage Example

using Radiomics

# Load your 2D binary mask and define pixel spacing
mask = load_binary_mask("path/to/mask.nii")
spacing = [1.0f0, 1.0f0]  # pixel spacing in mm

# Extract 2D shape features
features = get_shape2d_features(mask, spacing, verbose=true)

# Access individual features
println("Perimeter: ", features["Perimeter"])
println("Sphericity: ", features["Sphericity"])
println("Elongation: ", features["Elongation"])

Clinical Applications

2D shape features are valuable in various medical imaging scenarios:

  • Lesion characterization and classification
  • Tumor margin assessment
  • Growth pattern analysis
  • Surgical planning and risk stratification
  • Treatment response monitoring