TensorToLine2D
Overview
TensorToLine2D decodes a spatial model output channel into an ordered Line2D polyline by thresholding, skeletonizing with Zhang-Suen thinning, and tracing connected skeleton pixels.
Header: src/DeepLearning/channel_decoding/TensorToLine2D.hpp
Registry: DecoderFactory::create("TensorToLine2D") — outputTypeName() is "Line2D"
Dispatched via DecoderDispatch when OutputBindingData::decoder holds LineDecoderParams.
Parameters
struct LineDecoderParams {
float threshold = 0.5f;
};Tensor layout
The decoder expects a 4D tensor in NCHW order:
| Dim | Name | Indexed by |
|---|---|---|
| 0 | Batch | DecoderContext::batch_index |
| 1 | Channel | DecoderContext::source_channel |
| 2 | Height | DecoderContext::height |
| 3 | Width | DecoderContext::width |
DecoderContext::height and DecoderContext::width must match tensor.size(2) and tensor.size(3) respectively.
The selected channel is converted to CPU float32 before thresholding.
Pipeline
- Threshold channel activations using
LineDecoderParams::threshold(strict>) - Skeletonize the binary mask to a 1-pixel-wide centerline (Zhang-Suen thinning)
- Find a skeleton endpoint (pixel with one neighbor), or any skeleton pixel for closed loops
- Trace connected skeleton pixels into an ordered polyline
- Scale coordinates to
DecoderContext::target_image_sizewhen non-zero
Returns an empty Line2D when no pixels exceed the threshold or the skeleton is empty.
Coordinate scaling
When DecoderContext::target_image_size is non-zero, polyline vertices are scaled linearly from tensor space to the original image size.
When target_image_size is {0, 0}, coordinates are returned in tensor pixel space.
Validation
decode() validates at runtime:
- Tensor is defined and 4-dimensional
batch_indexandsource_channelare in rangeheightandwidthare positive and match the tensor spatial dimensions
Invalid inputs throw std::invalid_argument or std::out_of_range after logging at spdlog::debug level.
Tests
tests/DeepLearning/channel_decoding/TensorToLine2D.test.cpp — horizontal and vertical lines, scaling, batch/channel selection, empty input, validation errors.
Filter with ctest -R "TensorToLine2D".