Adaptive Thresholds Confusion

Can someone tell me what parameters are in these Adaptive Threshold features and how they control black and white pixels.

cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,\ cv2.THRESH_BINARY,11,2) th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\ cv2.THRESH_BINARY,11,2) 
+6
source share
2 answers
 Python: cv2.adaptiveThreshold(src, maxValue, adaptiveMethod, thresholdType, blockSize, C[, dst]) → dst 

Options:

 src – Source 8-bit single-channel image. dst – Destination image of the same size and the same type as src . maxValue – Non-zero value assigned to the pixels for which the condition is satisfied. See the details below. adaptiveMethod – Adaptive thresholding algorithm to use, ADAPTIVE_THRESH_MEAN_C or ADAPTIVE_THRESH_GAUSSIAN_C . See the details below. thresholdType – Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV . blockSizeSize of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on. C – Constant subtracted from the mean or weighted mean (see the details below). Normally, it is positive but may be zero or negative as well. 

Taken from here: and also explains this method in more detail.

+7
source

Add to the answer from GPPK.

The function converts a grayscale image into a binary image in accordance with the formulas:

  • THRESH_BINARY

enter image description here

  • THRESH_BINARY_INV

enter image description here

where T (x, y) is the threshold calculated individually for each pixel.

  • For the ADAPTIVE_THRESH_MEAN_C method, the threshold value T (x, y) is the average for the blockSize x blockSize (x, y) minus C.
  • For the ADAPTIVE_THRESH_GAUSSIAN_C method, the threshold value T (x, y) is the weighted sum (cross-correlation with a Gaussian window) of the blockSize block x blockSize (x, y) minus C. The default sigma (standard deviation) is used for the specified block.
0
source

Source: https://habr.com/ru/post/983098/


All Articles