-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShear_algorithm.py
More file actions
77 lines (60 loc) · 1.99 KB
/
Shear_algorithm.py
File metadata and controls
77 lines (60 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Important imports for image processing
import cv2
import numpy as np
# Basic image reading
img = cv2.imread("mig.JPG", 0)
# Shearing factors in X and Y direction
Bx = 1
By = 1
# imread rows and columns
rows = img.shape[0]
cols = img.shape[1]
# Image copies
CopyOf_img1 = np.zeros((rows + cols, cols, 3), np.uint8)
CopyOf_img2 = np.zeros((rows + cols, cols, 3), np.uint8)
CopyOf_img3 = np.zeros((rows, cols + rows, 3), np.uint8)
CopyOf_img4 = np.zeros((rows, cols + rows, 3), np.uint8)
def shearAlgorithm():
# ShearX algorithm(s)
for i in range(0, rows):
for j in range(0, cols):
n = Bx * i
k = img[i, j]
if i >= 0 and i <= rows and j >= 0 and j <= cols:
CopyOf_img3[i, j + n] = k
for i in range(0, rows):
for j in range(0, cols):
n = Bx * i
k = img[i, j]
if i >= 0 and i <= rows and j >= 0 and j <= cols:
CopyOf_img4[i, j - n + rows] = k
# ShearY algorithm(s)
for i in range(0, rows):
for j in range(0, cols):
n = By * j
k = img[i, j]
if i >= 0 and i <= rows and j >= 0 and j <= cols:
CopyOf_img1[i + n, j] = k
for i in range(0, rows):
for j in range(0, cols):
n = By * j
k = img[i, j]
if i >= 0 and i <= rows and j >= 0 and j <= cols:
CopyOf_img2[i - n + cols, j] = k
# Default image
cv2.imshow("defult", img)
# show shearY
cv2.imshow("shearY1", CopyOf_img1)
cv2.imshow("shearY2", CopyOf_img2)
# Show shearX
cv2.imshow("shearX1", CopyOf_img3)
cv2.imshow("shearX2", CopyOf_img4)
# Writes images to folder and saves them
cv2.imwrite('shearY1.PNG', CopyOf_img1)
cv2.imwrite('shearY2.PNG', CopyOf_img2)
cv2.imwrite('shearX1.PNG', CopyOf_img3)
cv2.imwrite('shearX2.PNG', CopyOf_img4)
# Any key can be pressed to destroy the image and exit out
cv2.waitKey(0)
cv2.destroyAllWindows()
shearAlgorithm()