Welcome to My Blog 👋

Java, Spring Framework, Microservices, Docker, Kubernetes, AWS and Others 🚀
Follow Me

Görüntü İşleme Dersleri Hafta 12 - ÇOMÜ



  December 23, 2017    Labels:,, 


6
import matplotlib.pyplot as plt
7
import numpy as np
8
import math
9
10
def get_shear_matrix_for_factor_x(factor_x: int):
11
shear_m=np.empty((2,2),np.float)
12
shear_m[0,:] = np.array([1,factor_x])
13
shear_m[1, :] = np.array([0,1])
14
return shear_m
15
16
def get_rotation_matrix_for_angle(angle: float):
17
theta = angle
18
rotation_matrix = np.array([[math.cos(theta), -math.sin(theta)], [math.sin(theta), math.cos(theta)]], np.float)
19
20
return rotation_matrix
21
def get_new_point(point: tuple, angle: float):
22
"""
23
:param point: a point in 2D, with coordinates x, y
24
:param angle: in radians
25
:return: tuple representing a point with ratoted coordinates
26
"""
27
rotation_matrix = get_rotation_matrix_for_angle(angle)
28
29
point_vector=np.empty((2,1),float)
30
31
point_vector[0,0]=point[0]
32
point_vector[1,0]=point[1]
33
34
new_point = np.matmul(rotation_matrix, point)
35
36
x = int(new_point[0])
37
y = int(new_point[1])
38
39
return (x,y)
40
41
def display_plot(points):
42
"""
43
:param points: np.matrix
44
"""
45
46
point_list_x = points[:, 0] #
47
point_list_y = points[:, 1] # [
48
49
plt.plot(point_list_x, point_list_y)
50
plt.show()
51
def get_my_T():
52
points=np.empty((9,2),np.float)
53
points[:,0] = np.array([20,25,25,35,35,10,10,20,20])
54
points[:,1] = np.array([ 0, 0,30,30,35,35,30,30, 0])
55
56
return points
57
58
def display_three_letters_on_same_plot(p_1: np.matrix , p_2: np.matrix, p_3: np.matrix):
59
plt.plot(p_1[:,0], p_1[:,1],color="red")
60
plt.plot(p_2[:, 0], p_2[:, 1], color="yellow")
61
plt.plot(p_3[:, 0], p_3[:, 1], color="green")
62
plt.xlim([-100,100])
63
plt.ylim([-100,100])
64
plt.show()
65
66
67
def display_two_letters_on_same_plot(p_1: np.matrix , p_2: np.matrix):
68
plt.plot(p_1[:,0], p_1[:,1],color="red")
69
plt.plot(p_2[:, 0], p_2[:, 1], color="yellow")
70
plt.show()
71
def display_points(points):
72
plt.plot(points[:,0], points[:,1])
73
plt.show()
74
75
def rotate_a_letter_by_angle(letter:np.matrix,angle:np.float):
76
m,n=letter.shape
77
new_points = np.empty((m,n),np.float)
78
for i in range(m):
79
new_points[i,:] = get_new_point(letter[i,:],angle)
80
return new_points
81
82
def shear_a_letter_by_factor_x(letter:np.matrix,factor_x:np.int):
83
m,n=letter.shape
84
new_letter = np.empty((m,n),np.float)
85
shear_matrix=get_shear_matrix_for_factor_x(factor_x)
86
for i in range(m):
87
new_letter[i,:] = np.matmul(shear_matrix,letter[i,:])
88
89
return new_letter
90
91
92
p=get_my_T()
93
p_1=rotate_a_letter_by_angle(get_my_T(), np.pi/2)
94
p_2=shear_a_letter_by_factor_x(p,1)
95
# display_two_letters_on_same_plot(p,p_2)
96
display_three_letters_on_same_plot(p,p_1,p_2)
97
# display_points(p_2)


No comments:

Post a Comment