#Shift all pixels left a few spaces... #See slide number 21 from IrfanEssa-CP-02-5-Filtering.pdf # # 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("Original") cv2.namedWindow("Shifted") #Load source / input image as grayscale, also works on color images... imgIn = cv2.imread("oscar.jpg", cv2.IMREAD_GRAYSCALE) cv2.imshow("Original", imgIn) #Create the identity filter, but with the 1 shifted to the right! kernel = np.zeros( (9,9), np.float32) kernel[4,7] = 1.0 #Identity, shifted right! #cv2.BORDER_CONSTANT default to black. Without this borderType specified, #it will default to something else, probably replicate or reflect... #and that makes it very hard to see the effect with only a 2 pixel shift... custom = cv2.filter2D(imgIn, -1, kernel, borderType = cv2.BORDER_CONSTANT) cv2.imshow("Shifted", custom) cv2.waitKey(0)