Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

cv2.adaptiveThreshold() 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 :: rabbitmq pika username password 
Python :: how to graph with python 
Python :: dict godot 
Python :: django message framework 
Python :: spike python 
Python :: goal parser 
Python :: dropping unnamed columns in pandas 
Python :: pandas describe get mean min max 
Python :: flask for loops 
Python :: drop index in multiindex pandas 
Python :: python rock paper scissor 
Python :: remover espaços string python 
Python :: jupyter themes 
Python :: python change base function 
Python :: how to change web browser in python 
Python :: python get time difference in milliseconds 
Python :: how to drop a column by name in pandas 
Python :: tkinter clear entry 
Python :: Writing Bytes to a File in python 
Python :: count number of words in a string python 
Python :: python save .mat 
Python :: discord python bot require one of two roles for command 
Python :: delete index in df 
Python :: subtract one list from another python 
Python :: climate change 
Python :: python sftp put file 
Python :: python get all ips in a range 
Python :: how to get user input of list in python 
Python :: create sqlite database python 
Python :: space to underscore python 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =