MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ apply_contour_mask()

MAYAFLUX_API void MayaFlux::Kinesis::Vision::apply_contour_mask ( std::span< float >  pixels,
uint32_t  w,
uint32_t  h,
uint32_t  channels,
const Contour &  contour,
float  origin_x,
float  origin_y,
float  scale_x,
float  scale_y 
)

Zero all pixels in pixels that fall outside contour.

For each pixel in the buffer, reconstructs its normalised image-space position from its row/column index, the crop origin (origin_x, origin_y), and the pixel dimensions. Tests containment using the winding number algorithm against the contour's point polygon. Pixels outside the polygon have all channel values set to 0.

The buffer is modified in place. Pixels inside the polygon are untouched.

Parameters
pixelsInterleaved float buffer, size must be w * h * channels.
wBuffer width in pixels.
hBuffer height in pixels.
channelsChannels per pixel.
contourContour whose polygon defines the keep region.
origin_xNormalised x coordinate of the buffer's left edge.
origin_yNormalised y coordinate of the buffer's top edge.
scale_xNormalised width covered by one pixel column.
scale_yNormalised height covered by one pixel row.

Definition at line 226 of file Contours.cpp.

233{
234 if (pixels.empty() || contour.points.empty() || channels == 0)
235 return;
236
237 for (uint32_t row = 0; row < h; ++row) {
238 const float py = origin_y + (static_cast<float>(row) + 0.5F) * scale_y;
239 for (uint32_t col = 0; col < w; ++col) {
240 const float px = origin_x + (static_cast<float>(col) + 0.5F) * scale_x;
241 if (!point_in_contour(contour.points, px, py)) {
242 const size_t base = (static_cast<size_t>(row) * w + col) * channels;
243 for (uint32_t c = 0; c < channels; ++c)
244 pixels[base + c] = 0.0F;
245 }
246 }
247 }
248}
const std::vector< float > * pixels
Definition Decoder.cpp:48
uint32_t h
Definition InkPress.cpp:29
uint32_t channels
uint32_t py
uint32_t px
std::vector< glm::vec2 > points
Definition Features.hpp:49

References channels, h, pixels, MayaFlux::Kinesis::Vision::Contour::points, px, and py.