Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- img = cv2.imread("2.PNG", 0)
- rows = img.shape[0]
- cols = img.shape[1]
- shearX = np.ones((rows, cols), np.uint8)
- if img is None:
- print('No image loaded')
- exit()
- # Bx: x-shear parameter Shx
- Bx = 0.5
- # By: y-shear parameter Shy
- By = 0.0
- # Matrix factors Chp:10 in book
- a1 = 1
- a2 = Bx
- a3 = 0
- b1 = By
- b2 = 1
- b3 = 0
- r1 = 0
- c1 = 0
- # Mapping offset
- maxYOffset = abs(cols * Bx)
- maxXOffset = abs(rows * By)
- # affine array 3x3 x-shear
- affinAry = np.array(
- [[a1, a2, a3],
- [b1, b2, b3],
- [0, 0, 1]])
- for r in range(0, rows):
- for c in range(0, cols):
- r1 = r + c * By - maxYOffset
- c1 = r * Bx + c - maxXOffset
- if r1 >= 0 and r1 <= rows and c1 >= 0 and c1 <= cols: # check if the point is within the boundaries
- shearX[r, c] = img[r1, c1]
- print(shearX)
- print(maxYOffset)
- print(maxXOffset)
- print(r1)
- print(c1)
- print(shearX)
- cv2.imshow('norm', img)
- cv2.imshow('shear', shearX)
- cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement