MayaFlux 0.5.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 211 of file Contours.cpp.

218{
219 if (pixels.empty() || contour.points.empty() || channels == 0)
220 return;
221
222 for (uint32_t row = 0; row < h; ++row) {
223 const float py = origin_y + (static_cast<float>(row) + 0.5F) * scale_y;
224 for (uint32_t col = 0; col < w; ++col) {
225 const float px = origin_x + (static_cast<float>(col) + 0.5F) * scale_x;
226 if (!point_in_contour(contour.points, px, py)) {
227 const size_t base = (static_cast<size_t>(row) * w + col) * channels;
228 for (uint32_t c = 0; c < channels; ++c)
229 pixels[base + c] = 0.0F;
230 }
231 }
232 }
233}
const std::vector< float > * pixels
Definition Decoder.cpp:65
uint32_t h
Definition InkPress.cpp:28
std::vector< glm::vec2 > points
Definition Features.hpp:43

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

Referenced by MayaFlux::Yantra::VisionExtractor< InputType, OutputType >::extract_implementation().

+ Here is the caller graph for this function: