Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

adaptive thresholding

'''Adaptive thresholding assumes that smaller regions of the image
are most likely to have approximately constant level of light.
The adaptive threshold can be performed by cv2.adaptiveThreshold()
as follows in the example:'''

img = cv2.imread("myimage.png")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #Convert to grayscale
lowpass = cv2.GaussianBlur(gray, (7, 7), 0) #Filter high frequency noise.
''' all pixel values above adaptive threshold T will be set to 255 
else zero, this is accomplished by cv2.THRESH_BINARY method which create
a binary image in the neighborhood region. ADAPTIVE_THRESH_MEAN_C 
specifies that adptive threshod T is calculated by neighbourhood mean.
20 is the size of the filter 19X19 (must be odd). 8 is
the fine tuning value used to improve adptive threshold (is arbitrary).
'''
thresh = cv2.adaptiveThreshold(lowpass, 255,cv2.ADAPTIVE_THRESH_MEAN_C,
                               cv2.THRESH_BINARY,19, 8)
#cv2.ADAPTIVE_THRESH_MEAN_C can be subtituded by
#cv2.ADAPTIVE_THRESH_GAUSSIAN_C which is a weighted mean. 
cv2.imshow("Mean Adaptive Thresholding", thresh)
cv2.waitKey(0)
Comment

PREVIOUS NEXT
Code Example
Python :: how to make nmap port scanner in python 
Python :: splitting a string and appending each character to a list python 
Python :: selenium refresh till the element appears python 
Python :: django read mesage 
Python :: write muli line conditional statements in python 
Python :: Goal Parser Python 
Python :: drop unamed columns in pandas 
Python :: dataclass post init 
Python :: generate random integer matrix python 
Python :: python command not found 
Python :: read all text file python 
Python :: python local server command 
Python :: install biopython in windows 
Python :: polarean share price 
Python :: python pyautogui screenshot 
Python :: python version command notebook 
Python :: drop columnd python 
Python :: flip pyplot python 
Python :: how to move the pointer on screen using python 
Python :: one line input in python 
Python :: install python package from git colab 
Python :: what is a good python version today 
Python :: from time import sleep, time 
Python :: filter list dict 
Python :: python save input to text file 
Python :: how to check if two columns match in pandas 
Python :: simulated annealing python 
Python :: dire Bonjour en python 
Python :: mouse module python 
Python :: python- number of row in a dataframe 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =