#Shift all pixels left 4 spaces spaces... #See slide number 21 from IrfanEssa-CP-02-5-Filtering.pdf # # Jay Summet 2024 # #Python 3.10, OpenCV 4.5.4 # import cv2 import numpy as np #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 far right! kernel = np.zeros( (9,9), np.float32) kernel[4,8] = 1.0 #Identity, but shifted to far right! print(kernel) #cv2.BORDER_CONSTANT default to black. Without this borderType specified, #it will default to Reflection_101 #and that makes it very hard to see the effect with only a 4 pixel shift... custom = cv2.filter2D(imgIn, -1, kernel, borderType = cv2.BORDER_CONSTANT) cv2.imshow("Shifted", custom) cv2.waitKey(0) cv2.startWindowThread()