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 :: intersection of dataframes based on column 
Python :: python subtract 2 strings 
Python :: python launch file 
Python :: installing more modules in pypy 
Python :: random element python 
Python :: python list inversion 
Python :: not importing local folder python 
Python :: remove warnings from jupter notebook 
Python :: python head function show all columns 
Python :: python convert int to bool 
Python :: how to get the current url path in django template 
Python :: python class get attribute by name 
Python :: py pause script 
Python :: how to check if a number is odd python 
Python :: remove jupyter environment 
Python :: seconds in a month 
Python :: How to make an simple python client 
Python :: colored text python 
Python :: python print exception 
Python :: except do nothing python 
Python :: create pdf from images python 
Python :: is there a python command that clears the output 
Python :: how to convert string to function name in python 
Python :: python remove stop words 
Python :: read tsv file column 
Python :: all column except pandas 
Python :: create a vector of zeros in r 
Python :: tuple in godot 
Python :: python negation of an statement 
Python :: how to set icon in tkinter 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =