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

◆ threshold_adaptive() [1/2]

MAYAFLUX_API void MayaFlux::Kinesis::Vision::threshold_adaptive ( std::span< const float >  gray,
std::span< float >  dst,
uint32_t  w,
uint32_t  h,
uint32_t  block_size,
float  offset 
)

Adaptive threshold writing into caller-supplied buffer.

Each pixel is thresholded against the mean of its block_size x block_size neighbourhood minus offset. Pixels at the border use a clamped neighbourhood.

Parameters
grayInput span, size must be w * h.
dstOutput span, size must be w * h.
wImage width in pixels.
hImage height in pixels.
block_sizeNeighbourhood size in pixels. Must be odd and >= 3.
offsetSubtracted from local mean before comparison.

Definition at line 238 of file PixelOps.cpp.

242{
243 const size_t n = static_cast<size_t>(w) * h;
244 const auto half = static_cast<int32_t>(block_size / 2);
245
246 std::for_each(std::execution::par_unseq,
247 std::views::iota(size_t { 0 }, n).begin(),
248 std::views::iota(size_t { 0 }, n).end(),
249 [&](size_t idx) {
250 const auto px = static_cast<int32_t>(idx % w);
251 const auto py = static_cast<int32_t>(idx / w);
252
253 float sum = 0.0F;
254 int32_t count = 0;
255
256 for (int32_t dy = -half; dy <= half; ++dy) {
257 const int32_t ny = std::clamp(py + dy, 0, static_cast<int32_t>(h) - 1);
258 for (int32_t dx = -half; dx <= half; ++dx) {
259 const int32_t nx = std::clamp(px + dx, 0, static_cast<int32_t>(w) - 1);
260 sum += gray[static_cast<size_t>(ny) * w + nx];
261 ++count;
262 }
263 }
264
265 const float mean = sum / static_cast<float>(count);
266 dst[idx] = gray[idx] >= (mean - offset) ? 1.0F : 0.0F;
267 });
268}
uint64_t offset
Definition Composite.cpp:10
uint32_t h
Definition InkPress.cpp:29
uint32_t * dst
size_t count
uint32_t py
uint32_t px
std::vector< double > sum(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Sum per window.
Definition Analysis.cpp:469
std::vector< double > mean(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Arithmetic mean per window.
Definition Analysis.cpp:200

References count, dst, h, offset, px, and py.

Referenced by MayaFlux::Kinesis::Vision::VisionExecutor::run(), and threshold_adaptive().

+ Here is the caller graph for this function: