# Bluring/Smoothing example using a 1D Gaussian Kernel # We show how a 1D kernel is not the same as a 2D kernel, # See the smoothing_separable.py example to show how to use separable # 1D kernels to emulate the 2D kernel application, but much faster. # # # Jay Summet 2015 # #Python 2.7, OpenCV 2.4.x # import cv2 import numpy as np #Linux window threading setup code. cv2.startWindowThread() cv2.namedWindow("Difference") cv2.namedWindow("Gaussian Blur") cv2.namedWindow("Gaussian 1D Blur") #Load source / input image as grayscale, also works on color images... imgIn = cv2.imread("blueSky.jpg", cv2.IMREAD_GRAYSCALE) # 1D Gausian Kernel using sigma of 1.7 kernel = cv2.getGaussianKernel( 11, 1.7 ) #If you transpose the kernel the 1D filter operation is oriented # horizontally instead of vertically. #kernel = np.transpose(kernel) oneD = cv2.filter2D(imgIn, -1, kernel) cv2.imshow("Gaussian 1D Blur", oneD) gBlurImg = cv2.GaussianBlur(imgIn, (11,11), 1.7) cv2.imshow("Gaussian Blur", gBlurImg) #This technique (differencing two images and showing the result) # is a good general purpose way to compare two very similar, but not # quite the same images to more easily identify the differences. diff = oneD- gBlurImg cv2.imshow("Difference", diff) cv2.waitKey(0)