Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

adaptive thresholding 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 :: adaptive thresholding 
Python :: rabbitmq pika username password 
Python :: standardscaler in machine learning 
Python :: mean class accuracy sklearn 
Python :: likeliness python 
Python :: how to map array of string to int in python 
Python :: pyhton return annonymous object 
Python :: python http server command line 
Python :: how to check if a message includes a word discord.py 
Python :: fatal error detected failed to execute script 
Python :: Remove the First Character From the String in Python Using the Slicing 
Python :: write to file python 3 
Python :: opencv histogram equalization 
Python :: How to log a python crash? 
Python :: save image url to png python 
Python :: drop rows with certain values pandas 
Python :: python list rotation 
Python :: python dict order a dict by key 
Python :: tkinter button background color mac 
Python :: arabic in python 
Python :: python writelines newline 
Python :: python poner en mayusculas 
Python :: fill a list with random numbers 
Python :: how to insert sound in python 
Python :: how to Take Matrix input from user in Python 
Python :: python time function duration and memory usage 
Python :: reset index with pandas 
Python :: SafeERC20: low-level call failed 
Python :: codeforces 677a solution 
Python :: lda scikit learn 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =