Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

adaptive thresholding cv2 python

'''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 :: cv2.adaptiveThreshold() 
Python :: django datetimefield default 
Python :: pandas convert all string columns to lowercase 
Python :: python n choose r 
Python :: the user to enter their name and display each letter in their name on a separate line python 
Python :: django genericforeignkey null 
Python :: alarm when code finishes 
Python :: suppress warning jupyter notebook 
Python :: wait() in python tkinter 
Python :: np zeros in more dimensions 
Python :: convert files from jpg to png and save in a new directory python 
Python :: sort by index pandas 
Python :: turn of warning iin python 
Python :: oppsite of abs() python 
Python :: how to print an input backwards in python 
Python :: python tkinter delete label 
Python :: static dir in django python 
Python :: how to print dataframe in python without index 
Python :: python make api request 
Python :: requests post with headers python 
Python :: python-binance 
Python :: how to make a never ending loop in python 
Python :: python reduce function to sum array 
Python :: string pattern matching pandas 
Python :: regex in python to obtain only the string in python 
Python :: python check variable is tuple 
Python :: window in python 
Python :: if you assign the result a void function to a variable in python, you get: 
Python :: internet explorer selenium 
Python :: python get min max value from a dictionary 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =