Skip to content

AdaptiveBinarize

Julek edited this page Oct 6, 2024 · 2 revisions

Adaptive Binarize for Vapoursynth, based on OpenCV's Adaptive Thresholding.

Usage

vszip.AdaptiveBinarize(vnode clip, vnode clip2[, int c=3])

Parameters:

  • clip
    A clip to process. It must be in YUV/GRAY 8-bit.

  • clip2
    Blurred clip to calculate the thresholding.
    Gauss has a cleaner result and Mean/BoxBlur retains more detail.

  • c
    Controls the threshold, read the OpenCV doc for more details.
    Default: 3.

Example

This code in Vapoursynth:

import vstools
import vapoursynth as vs
core = vs.core

src8 = ...
luma = vstools.get_y(src8)
luma16 = vstools.depth(luma, 16)
blur16 = luma16.std.Convolution([1]*11, mode='hv')
blur8 = vstools.depth(blur16, 8)
binarize = core.vszip.AdaptiveBinarize(luma, blur8, c=3)

Has the same result as this in OpenCV:

binarize = cv.adaptiveThreshold(img, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY_INV, 11, 3)

More example: flat_mask from jvsfunc

Clone this wiki locally