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

◆ normalised_rect_to_region()

MAYAFLUX_API Region MayaFlux::Kakshya::normalised_rect_to_region ( float  nx,
float  ny,
float  nw,
float  nh,
uint32_t  pixel_w,
uint32_t  pixel_h 
)

Convert a normalised image rectangle to a pixel-space Region.

Input coordinates are in image space: origin top-left, x and y in [0, 1], +Y downward. Output Region uses the IMAGE_COLOR coordinate convention: start/end as { y0, x0 } / { y1, x1 } (inclusive, clamped to [0, w-1] x [0, h-1]).

This is the inverse of the normalisation performed by ConnectedComponents and Contours, and is the correct input form for get_region_data() on any pixel-bearing SignalSourceContainer.

Parameters
nxNormalised left edge in [0, 1].
nyNormalised top edge in [0, 1].
nwNormalised width in [0, 1].
nhNormalised height in [0, 1].
pixel_wSource image width in pixels.
pixel_hSource image height in pixels.
Returns
Region with 2D spatial coordinates in pixel integers.

Definition at line 377 of file CoordUtils.cpp.

380{
381 const auto fw = static_cast<float>(pixel_w);
382 const auto fh = static_cast<float>(pixel_h);
383
384 const auto x0 = static_cast<uint64_t>(std::clamp(nx * fw, 0.0F, fw - 1.0F));
385 const auto y0 = static_cast<uint64_t>(std::clamp(ny * fh, 0.0F, fh - 1.0F));
386 const auto x1 = static_cast<uint64_t>(std::clamp((nx + nw) * fw - 1.0F, 0.0F, fw - 1.0F));
387 const auto y1 = static_cast<uint64_t>(std::clamp((ny + nh) * fh - 1.0F, 0.0F, fh - 1.0F));
388
389 return Region(std::vector { y0, x0 }, std::vector { y1, x1 });
390}
Represents a point or span in N-dimensional space.
Definition Region.hpp:73

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

+ Here is the caller graph for this function: