Class AutoTracer
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
ConstructorsConstructorDescriptionAutoTracer(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 TypeMethodDescriptionintGets 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.
-
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 tracetransformer- the coordinate transformer for pixel-to-data conversionstartPixelX- the starting x pixel coordinate (inclusive)endPixelX- the ending x pixel coordinate (inclusive)
-
-
Method Details
-
traceDataset
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 flagseedPixelX- seed X coordinate in image pixelsseedPixelY- seed Y coordinate in image pixelswindowHalfHeight- 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 matchuseSecondaryYAxis- whether to convert Y using secondary axisseedPixelX- seed X in image pixelsseedPixelY- seed Y in image pixelswindowHalfHeight- vertical search half-windowtolerance- RGB distance tolerance to accept a matchmaxGap- maximum consecutive missed columns allowedlookahead- maximum horizontal columns to search ahead to bridge dashes- Returns:
- traced points in data coordinates
-