Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

cv2.GaussianBlur()

import cv2
from matplotlib import pyplot as plt
'''Read your image and convert it to graycale as follows:'''
img = cv2.imread("myimage.jpg")
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
'''Apply a Low-pass filter such as guassian blur to reduce high frequency
components as follows:'''
img_blur = cv2.GaussianBlur(gray, (3,3), 0) 
'''The (3,3) is filter size (must be odd) and zero is the standard
deviation parameter of a guassian function which tells GaussianBlur to
calculate standard diviation automatically. Assuming myimage.jpg is of a
bi-modal distribution (its histogram plot contains two peaks) then 
threshold is applied as follows:'''
threshdimage = cv2.threshold(img_blur,100,255,cv2.THRESH_BINARY)[1]
plt.imshow(threshdimage, cmap = 'gray', interpolation = 'bicubic')# plot  
plt.xticks([]), plt.yticks([])  # to hide tick values on X and Y axis
'''Where 100 is threshold that divides the pixel space , hence all pixel
values smaller than 100 are set to 0 and all above 100 are set to 255.
The THRESH_BINARY specifies method used for thresholding. See the 
following: https://docs.opencv.org/4.x/d7/d4d/tutorial_py_thresholding.html
for more info'''
plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: f string decimal places 
Python :: nlargest 
Python :: combine 2 dataframes based on equal values in columns 
Python :: python 3 play sound 
Python :: except do nothing python 
Python :: rename files in folder python 
Python :: type hint tuple 
Python :: install python package from git colab 
Python :: drop second column pandas 
Python :: how to use colorama 
Python :: code for making an exe file for python 
Python :: fill a list with random numbers 
Python :: how to get the year in python 
Python :: python matplotlib hist set axis range 
Python :: open csv file in python 
Python :: pyqt tex 
Python :: all column except pandas 
Python :: python read arguments 
Python :: join on column pandas 
Python :: get cpu count in python 
Python :: python delete header row 
Python :: read_csv Unnamed: 0 
Python :: pycharm remove not in use imports 
Python :: find nan values in a column pandas 
Python :: pythom datetime now 
Python :: how to iterate through a text file in python 
Python :: multivariate outlier detection python 
Python :: python sorting array without inbuilt sort 
Python :: pandas string does not contain 
Python :: plt normalized histogram 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =