Created
October 1, 2017 23:05
-
-
Save nhomble/68fc95c87e9cc208795d73059f2e8854 to your computer and use it in GitHub Desktop.
Try gaussian smoothing across different scenarios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import matplotlib.pyplot as plt | |
kernel = (7, 7) | |
imgs = { | |
"salt_n_pepper": cv2.imread("Noise_salt_and_pepper.png"), # thank you wikipedia | |
"wrinkles": cv2.imread("old_man.jpeg"), # images.pexels.com | |
"tripod": cv2.imread("tripod.png") # classic b/w man looking at camera on tripod | |
} | |
''' | |
The thing is, gaussian smoothing cannot handle everything | |
''' | |
imgs["gauss_blur"] = cv2.GaussianBlur(imgs["salt_n_pepper"], kernel, 1) | |
imgs["median_blur"] = cv2.medianBlur(imgs["salt_n_pepper"], kernel[0]) | |
''' | |
And gaussian can ruin our sharp edges for edge detection | |
''' | |
imgs["gauss_edge"] = cv2.GaussianBlur(imgs["wrinkles"], kernel, 1) | |
imgs["bilat_edge"] = cv2.bilateralFilter(imgs["wrinkles"], 5, 10, 10) | |
imgs["gauss_canny"] = cv2.Canny(imgs["gauss_edge"], 0, 255) | |
imgs["bilat_canny"] = cv2.Canny(imgs["bilat_edge"], 0, 255) | |
''' | |
We can remove low frequency, gaussian pretty well though and avoids the inconsistency of the box filter for example | |
because of it's smooth freq domain shape. | |
''' | |
kernel = (17, 17) | |
imgs["gauss_tripod"] = cv2.GaussianBlur(imgs["tripod"], kernel, 1) | |
imgs["box_tripod"] = cv2.boxFilter(imgs["tripod"], -1, kernel) | |
for (k, v) in imgs.items(): | |
cv2.imshow(k, v) | |
''' | |
Along the way, I came across: http://docs.opencv.org/3.1.0/d4/d13/tutorial_py_filtering.html | |
''' | |
plt.plot([0], [0]) | |
plt.show(block=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment