You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
531 B
Python
18 lines
531 B
Python
import cv2
|
|
import numpy as np
|
|
|
|
|
|
|
|
def niBlackThreshold( src, blockSize, k, binarizationMethod= 0 ):
|
|
mean = cv2.boxFilter(src,cv2.CV_32F,(blockSize, blockSize),borderType=cv2.BORDER_REPLICATE)
|
|
sqmean = cv2.sqrBoxFilter(src, cv2.CV_32F, (blockSize, blockSize), borderType = cv2.BORDER_REPLICATE)
|
|
variance = sqmean - (mean*mean)
|
|
stddev = np.sqrt(variance)
|
|
thresh = mean + stddev * float(-k)
|
|
thresh = thresh.astype(src.dtype)
|
|
k = (src>thresh)*255
|
|
k = k.astype(np.uint8)
|
|
return k
|
|
|
|
|
|
# cv2.imshow() |