Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3.  
  4. img = cv2.imread("2.PNG", 0)
  5. rows = img.shape[0]
  6. cols = img.shape[1]
  7. shearX = np.ones((rows, cols), np.uint8)
  8.  
  9. if img is None:
  10.     print('No image loaded')
  11.     exit()
  12. # Bx: x-shear parameter  Shx
  13. Bx = 0.5
  14. # By: y-shear parameter  Shy
  15. By = 0.0
  16.  
  17. # Matrix factors   Chp:10 in book
  18. a1 = 1
  19. a2 = Bx
  20. a3 = 0
  21. b1 = By
  22. b2 = 1
  23. b3 = 0
  24. r1 = 0
  25. c1 = 0
  26.  
  27. # Mapping offset
  28. maxYOffset = abs(cols * Bx)
  29. maxXOffset = abs(rows * By)
  30.  
  31. # affine array 3x3 x-shear
  32. affinAry = np.array(
  33.     [[a1, a2, a3],
  34.      [b1, b2, b3],
  35.      [0, 0, 1]])
  36.  
  37. for r in range(0, rows):
  38.     for c in range(0, cols):
  39.         r1 = r + c * By - maxYOffset
  40.         c1 = r * Bx + c - maxXOffset
  41.  
  42.         if r1 >= 0 and r1 <= rows and c1 >= 0 and c1 <= cols: # check if the point is within the boundaries
  43.          shearX[r, c] = img[r1, c1]
  44.  
  45. print(shearX)
  46. print(maxYOffset)
  47. print(maxXOffset)
  48. print(r1)
  49. print(c1)
  50. print(shearX)
  51. cv2.imshow('norm', img)
  52. cv2.imshow('shear', shearX)
  53. cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement