Class AutoTracer

java.lang.Object
com.digitizer.image.AutoTracer

public class AutoTracer extends Object
Performs auto-trace of curves in images using color matching.

This class performs a per-column scan and selects the pixel whose color has the smallest RGB distance to the target dataset color. The resulting pixels are converted into Point coordinates using a provided CoordinateTransformer.

The algorithm is intentionally simple and robust; it is not a full image processing pipeline — for most cases it returns a plausible one-point-per-column representation of the curve that can then be post-processed or smoothed by callers.

Complexity: For an image of width W (scanned columns) and height H the trace performs O(W * H) color distance computations and uses O(W) additional memory for the output point list. This is acceptable for typical plot images; large images can be sub-sampled (adjust start/end pixel X) if needed.

  • Constructor Summary

    Constructors
    Constructor
    Description
    AutoTracer(javafx.scene.image.Image image, CoordinateTransformer transformer, int startPixelX, int endPixelX)
    Constructs an AutoTracer for the given image and coordinate transformation.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Gets the number of columns to be scanned during auto-trace.
    traceDataset(Dataset targetDataset)
    Performs auto-tracing of a curve using color matching.
    traceFromSeed(Dataset targetDataset, int seedPixelX, int seedPixelY, int windowHalfHeight, double tolerance, int maxGap)
    Performs a seed-based trace starting from a user-provided seed pixel.
    traceFromSeedColor(javafx.scene.paint.Color targetColor, boolean useSecondaryYAxis, int seedPixelX, int seedPixelY, int windowHalfHeight, double tolerance, int maxGap, int lookahead)
    Trace from a seed using an explicit target color and optional horizontal lookahead.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AutoTracer

      public AutoTracer(javafx.scene.image.Image image, CoordinateTransformer transformer, int startPixelX, int endPixelX)
      Constructs an AutoTracer for the given image and coordinate transformation.
      Parameters:
      image - the image to trace
      transformer - the coordinate transformer for pixel-to-data conversion
      startPixelX - the starting x pixel coordinate (inclusive)
      endPixelX - the ending x pixel coordinate (inclusive)
  • Method Details

    • traceDataset

      public List<Point> traceDataset(Dataset targetDataset)
      Performs auto-tracing of a curve using color matching. Scans column-by-column and selects the pixel with the minimum RGB distance to the target color.
      Parameters:
      targetDataset - the dataset whose color is used for matching
      Returns:
      a list of traced points in data coordinates
    • getColumnCount

      public int getColumnCount()
      Gets the number of columns to be scanned during auto-trace.
      Returns:
      the column count
    • traceFromSeed

      public List<Point> traceFromSeed(Dataset targetDataset, int seedPixelX, int seedPixelY, int windowHalfHeight, double tolerance, int maxGap)
      Performs a seed-based trace starting from a user-provided seed pixel. The algorithm follows the line left and right from the seed, constraining the vertical search to a small window around the previous hit. This helps follow dashed or interrupted lines and avoid jumping to other same-color regions.
      Parameters:
      targetDataset - dataset providing the target color and secondary Y flag
      seedPixelX - seed X coordinate in image pixels
      seedPixelY - seed Y coordinate in image pixels
      windowHalfHeight - vertical search window half-height in pixels (e.g. 8)
      tolerance - maximum RGB distance to accept a match (0..~1.732)
      maxGap - maximum consecutive columns to tolerate with no match before stopping
      Returns:
      traced points in data coordinates (one per found column)
    • traceFromSeedColor

      public List<Point> traceFromSeedColor(javafx.scene.paint.Color targetColor, boolean useSecondaryYAxis, int seedPixelX, int seedPixelY, int windowHalfHeight, double tolerance, int maxGap, int lookahead)
      Trace from a seed using an explicit target color and optional horizontal lookahead. This variant uses the sampled seed color (recommended for dashed lines) rather than the dataset's stored color.
      Parameters:
      targetColor - the color to match
      useSecondaryYAxis - whether to convert Y using secondary axis
      seedPixelX - seed X in image pixels
      seedPixelY - seed Y in image pixels
      windowHalfHeight - vertical search half-window
      tolerance - RGB distance tolerance to accept a match
      maxGap - maximum consecutive missed columns allowed
      lookahead - maximum horizontal columns to search ahead to bridge dashes
      Returns:
      traced points in data coordinates