MayaFlux 0.5.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 258 of file PixelOps.cpp.

262{
263 const size_t n = static_cast<size_t>(w) * h;
264 const auto half = static_cast<int32_t>(block_size / 2);
265
266 P::for_each(P::par_unseq,
267 std::views::iota(size_t { 0 }, n).begin(),
268 std::views::iota(size_t { 0 }, n).end(),
269 [&](size_t idx) {
270 const auto px = static_cast<int32_t>(idx % w);
271 const auto py = static_cast<int32_t>(idx / w);
272
273 float sum = 0.0F;
274 int32_t count = 0;
275
276 for (int32_t dy = -half; dy <= half; ++dy) {
277 const int32_t ny = std::clamp(py + dy, 0, static_cast<int32_t>(h) - 1);
278 for (int32_t dx = -half; dx <= half; ++dx) {
279 const int32_t nx = std::clamp(px + dx, 0, static_cast<int32_t>(w) - 1);
280 sum += gray[static_cast<size_t>(ny) * w + nx];
281 ++count;
282 }
283 }
284
285 const float mean = sum / static_cast<float>(count);
286 dst[idx] = gray[idx] >= (mean - offset) ? 1.0F : 0.0F;
287 });
288}
uint32_t h
Definition InkPress.cpp:28
size_t count
float offset
uint32_t block_size
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
double mean(const std::vector< double > &data)
Calculate mean of single-channel data.
Definition Yantra.cpp:55

References block_size, count, h, MayaFlux::mean(), and offset.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function: