from img-prep import *
otsu tresholding
- gray image
img = cv2.imread('image.png')
gray = toGray(img)
otsu_img = otsu_thresholding(gray)
otsu tresholding with gaussian blur
- gray image
img = cv2.imread('image.png')
gray = toGray(img)
otsu_img = gaussian_otsu_thresholding(gray)
normal thresholding
- gray image
img = cv2.imread('image.png')
gray = toGray(img)
final_img = global_thresholding(gray)
make image black & white (Binary)
- gray image
img = cv2.imread('image.png')
gray = toGray(img)
final_img = bw_image(gray)
edge detecting with auto lower and upper threshold detection. sigma=0.33 is basicaly best setup for most images.
- gray image
- slightly blurred
img = cv2.imread('image.png')
gray = toGray(img)
blurred = blur(gray)
final_img = edge_detection(blurred)
edge detecting using wide threshold
- gray image
- slightly blurred
img = cv2.imread('image.png')
gray = toGray(img)
blurred = blur(gray)
final_img = wide_edge_detection(blurred)
edge detecting using tight threshold
- gray image
- slightly blurred
img = cv2.imread('image.png')
gray = toGray(img)
blurred = blur(gray)
final_img = tight_edge_detection(blurred)
scale image with given percentage keeps aspect ratio
- none
img = cv2.imread('image.png')
scaled = percentage_scale(img, 50)
Convolves an image with a 5x5 kernel
- none
img = cv2.imread('image.png')
conv = convolution_2d(img)
Laplacian Edge detector
- gray image
- slightly blurred
img = cv2.imread('image.png')
gray = toGray(img)
blurred = blur(gray)
laplaced = laplacian(blurred)
Sobel Edge detector (X) for better edge detection it uses 64Bit in filter and outputs 8Bits
- none
img = cv2.imread('image.png')
final_img = sobelX(img)
Sobel Edge detector (Y) for better edge detection it uses 64Bit in filter and outputs 8Bits
- none
img = cv2.imread('image.png')
final_img = sobelY(img)
Shows image using Qt on Windows install Xming to use
- none
img = cv2.imread('image.png')
showImg(img)
Slightly blur image
- none
img = cv2.imread('image.png')
blurred = blur(img)
Convert to grayscale
- none
img = cv2.imread('image.png')
gray = toGray(img)
Convolution is an operation between every part of an image and an operator (kernel)
or
convolution is simply an element-wise multiplication of two matrices followed by a sum.
A kernel is essentially a fixed size array of numerical coefficeints along with an anchor point in that array, which is tipically located at the center.
The functions mostly use a 5x5 kernel using NumPy
kernel = np.ones((5,5),np.float32)/25
or 3x3 kernel defined in python lib
Laplacian edge detector uses only one kernel.
It calculates second order derivatives in a single pass
2nd order derivative, so it is extremely sensitive to noise
Original | Result |
---|---|
![]() |
![]() |
Sobel edge detector is a gradient based method based on the first order derivatives.
It calculates the first derivatives of the image separately for the X and Y axes.
Sobel uses 2x 3x3 kernels
first order derivatives
Sobel Kernel X | Sobel Kernel Y |
---|---|
![]() |
![]() |
Original |
---|
![]() |
Sobel X | Sobel Y |
---|---|
![]() |
![]() |