Skip to main content

dl::Mask2DEncoder

dl::Mask2DEncoder

Encodes a Mask2D (set of pixel coordinates) into a tensor channel. More…

#include <Mask2DEncoder.hpp>

Inherits from dl::ChannelEncoder

Public Functions

Name
virtual std::string name() const override
Human-readable name for UI / registry.
virtual std::string inputTypeName() const override
Which geometry type this encoder expects (e.g. “Point2D”, “Mask2D”).
void encode(Mask2D const & mask, ImageSize source_size, at::Tensor & tensor, EncoderContext const & ctx, Mask2DEncoderParams const & params)
Encode mask pixel set into tensor[batch_index, target_channel, :, :].

Additional inherited members

Public Functions inherited from dl::ChannelEncoder

Name
virtual ~ChannelEncoder() =default

Detailed Description

class dl::Mask2DEncoder;

Encodes a Mask2D (set of pixel coordinates) into a tensor channel.

Supported modes:

  • Binary: Sets 1.0 at each mask pixel (scaled to tensor dimensions)

Mask pixel coordinates are scaled from source ImageSize to (H, W).

Public Functions Documentation

function name

virtual std::string name() const override

Human-readable name for UI / registry.

Reimplements: dl::ChannelEncoder::name

function inputTypeName

virtual std::string inputTypeName() const override

Which geometry type this encoder expects (e.g. “Point2D”, “Mask2D”).

Reimplements: dl::ChannelEncoder::inputTypeName

function encode

static void encode(
    Mask2D const & mask,
    ImageSize source_size,
    at::Tensor & tensor,
    EncoderContext const & ctx,
    Mask2DEncoderParams const & params
)

Encode mask pixel set into tensor[batch_index, target_channel, :, :].

Parameters:

  • mask Set of pixel coordinates in source image coordinate space
  • source_size Spatial dimensions of the source image used to scale mask coordinates into tensor space
  • tensor Pre-allocated [B, C, H, W] float32 tensor to write into
  • ctx Encoder context (batch_index, target_channel, height, width)
  • params User-configurable encoding parameters (mode)

Precondition:

  • params.mode == Binary (enforcement: exception)
  • source_size.width > 0 and source_size.height > 0; zero causes floating-point division by zero producing a +Inf scale factor, which makes static_cast of the resulting Inf undefined behaviour (enforcement: none) [CRITICAL]
  • source_size.width > 0 and source_size.height > 0; negative values (e.g. the ImageSize default -1) produce a negative scale factor, mapping all mask pixels to coordinate 0 instead of their true position (enforcement: none) [IMPORTANT]
  • tensor is a valid initialized [B, C, H, W] float32 tensor with at least 4 dimensions; fewer dimensions cause an out-of-bounds tensor access when indexing tensor[batch_index][target_channel] (enforcement: none) [CRITICAL]
  • ctx.batch_index >= 0 and ctx.batch_index < tensor.size(0); an out-of-range value causes an out-of-bounds tensor access (enforcement: none) [CRITICAL]
  • ctx.target_channel >= 0 and ctx.target_channel < tensor.size(1); an out-of-range value causes an out-of-bounds tensor access (enforcement: none) [IMPORTANT]
  • ctx.height == tensor.size(2) and ctx.width == tensor.size(3); if either ctx dimension exceeds the actual tensor spatial dimension the accessor write is out-of-bounds (enforcement: none) [CRITICAL]
  • ctx.height > 0 and ctx.width > 0; zero causes std::clamp to receive an upper bound of -1 which is less than the lower bound of 0, invoking undefined behaviour (enforcement: none) [IMPORTANT]

An empty mask produces no output (no-op early return). Mask point coordinates outside the source image bounds are clamped to the tensor edges after scaling.


Updated on 2026-11-13 at 20:25:42 +0000