Skip to main content

TensorToPoint2D

Overview

TensorToPoint2D decodes peak locations from a spatial model output channel into Point2D<float> coordinates. It supports single-peak argmax decoding and multi-peak local-maximum detection.

Header: src/DeepLearning/channel_decoding/TensorToPoint2D.hpp
Registry: DecoderFactory::create("TensorToPoint2D") — outputTypeName() is "Point2D<float>"

DecoderDispatch and SlotAssembler call decode() only. decodeMultiple() is available for direct use but is not wired through dispatch.

Parameters

struct PointDecoderParams {
    bool subpixel = true;   // parabolic refinement around argmax / local maxima
    float threshold = 0.5f; // minimum activation for decodeMultiple()
};

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 peak detection.

Decode modes

decode() — single peak

  1. Flatten the channel and take the global argmax.
  2. If the peak value is <= 0, return {0, 0} (scaled to target image size when configured).
  3. Otherwise return integer pixel coordinates, optionally refined with parabolic subpixel fitting along each axis when params.subpixel is true.

decodeMultiple() — all local maxima

Returns every pixel that:

  • exceeds params.threshold, and
  • is strictly greater than all eight neighbors (local maximum)

Each peak is optionally subpixel-refined and scaled to target image coordinates.

Coordinate scaling

When DecoderContext::target_image_size is non-zero, coordinates are scaled linearly from tensor space to the original image size (dest = tensor * target / tensor_dim).

When target_image_size is {0, 0}, coordinates are returned in tensor pixel space.

Validation

Both entry points validate at runtime:

  • Tensor is defined and 4-dimensional
  • batch_index and source_channel are in range
  • height and width are 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/TensorToPoint2D.test.cpp — argmax, subpixel refinement, all-zero channel, scaling, batch/channel selection, decodeMultiple, validation errors.

Also covered by tests/DeepLearning/channel_decoding/RoundTrip.test.cpp encoder round-trips.

Filter with ctest -R "TensorToPoint2D".