Skip to main content

Line Resample

Overview

This transform resamples a line to either simplify its geometry or to ensure it has points that are evenly spaced.

Detailed Description

Line resampling is a common operation in data processing, used to either reduce the number of points in a line (simplification), smooth noisy geometry, or create a new line with a specific spacing between points. This transform provides three algorithms:

  • Fixed Spacing: This algorithm creates a new line with points that are a fixed distance apart. This is useful for standardizing the number of points in a line, or for preparing a line for further analysis that requires a uniform distribution of points.
  • Douglas-Peucker: This algorithm simplifies a line by removing points that are close to the line segment. This is useful for reducing the complexity of a line while preserving its overall shape.
  • Polynomial Smooth: Fits arc-length parametric polynomials to the line, then resamples the smoothed curve at the target spacing. Useful when the input line is noisy (for example from skeletonization or edge detection) but the overall shape should be preserved.

Neuroscience Use Cases

In neuroscience, line resampling can be used in a variety of applications:

  • Whisker Tracking: When tracking the movement of a whisker, the output is often a line with a variable number of points. Resampling the line to a fixed number of points can be useful for standardizing the data for further analysis, such as calculating the curvature or angle of the whisker over time.
  • Dendrite Tracing: When tracing the path of a dendrite from a neuron, the resulting line can be very complex. The Douglas-Peucker algorithm can be used to simplify the line, making it easier to visualize and analyze the overall shape of the dendrite.
  • Animal Tracking: When tracking the path of an animal in an open field, the resulting line can be very long and detailed. Resampling the line can help to smooth out the path and reduce the amount of data that needs to be processed.

Parameters

This transform has the following parameters:

  • algorithm: The resampling algorithm to use. This can be one of the following:
    • FixedSpacing (V1 UI: Fixed Spacing): Resamples the line to have points that are a fixed distance apart.
    • DouglasPeucker (V1 UI: Douglas-Peucker): Simplifies the line using the Douglas-Peucker algorithm.
    • PolynomialSmooth (V1 UI: Polynomial Smooth; V2 JSON: PolynomialSmooth): Smooths via parametric polynomial fitting, then resamples.
  • target_spacing: The desired distance between points in the resampled line. Used for FixedSpacing and PolynomialSmooth.
  • epsilon: The tolerance for the Douglas-Peucker algorithm. Used only when the algorithm is set to DouglasPeucker. A larger value of epsilon will result in a more simplified line.
  • polynomial_order: Polynomial order for PolynomialSmooth (typically 1–9, default 3). Requires at least polynomial_order + 1 input points for fitting.

Example Configuration

Here is a complete example of a JSON configuration file that could be used to run this transformation. This example smooths a noisy line with polynomial fitting and resamples at 5 pixel spacing (Transforms V2 / pipeline JSON uses method; V1 DataManager transform uses algorithm with display strings such as Polynomial Smooth).

[
    {
        "transformations": {
            "metadata": {
                "name": "Line Resample Pipeline",
                "description": "Test line resampling on line data",
                "version": "1.0"
            },
            "steps": [
                {
                    "step_id": "1",
                    "transform_name": "Resample Line",
                    "phase": "analysis",
                    "input_key": "test_lines",
                    "output_key": "resampled_lines",
                    "parameters": {
                        "algorithm": "Polynomial Smooth",
                        "target_spacing": 5.0,
                        "polynomial_order": 3,
                        "epsilon": 2.0
                    }
                }
            ]
        }
    }
]