Skip to content

Commit 8a9468b

Browse files
committed
task 2,3
1 parent 4c5f79e commit 8a9468b

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

‎task2.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ def main():
167167

168168
masked_image = apply_mask(point_img, mask)
169169

170+
op = masked_image*255/np.max(masked_image)
171+
170172

171173

172174
# apply threshold
@@ -176,14 +178,14 @@ def main():
176178
for i in range(h):
177179
for j in range(w):
178180

179-
if masked_image[i][j] < 135:
180-
masked_image[i][j] = 0
181-
181+
if op[i][j] < 45:
182+
op[i][j] = 0
183+
else:
184+
op[i][j] = 255
182185

183186

184-
op = masked_image/np.max(masked_image)
185187

186-
op = op*255
188+
187189

188190

189191
write_image(op, 'res_point')

‎task3.py‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,16 @@ def get_gaussian_kernel(sigma):
6868

6969
def edge_detection_x(img):
7070

71+
# x_kernel = [
72+
# [ 0, 1, 2],
73+
# [ -1, 0, 1],
74+
# [ -2, -1 , 0]
75+
# ]
76+
7177
x_kernel = [
72-
[ 0, 1, 2],
7378
[ -1, 0, 1],
74-
[ -2, -1 , 0]
79+
[ -2, 0, 2],
80+
[ -1, 0 , 1]
7581
]
7682

7783
edge_x_img = convolve_img(img,x_kernel,1)
@@ -115,12 +121,12 @@ def cast_vote(accumulator, x, y):
115121

116122
theta_rad = math.radians(theta)
117123

118-
p = ((x * math.cos(theta_rad)) + (y * math.sin(theta_rad)))
124+
p = int(round((x * math.cos(theta_rad)) + (y * math.sin(theta_rad))))
119125
# print(p)
120126

121127
# print(accumulator)
122128
if p<cl and p>-1:
123-
accumulator[theta+180][int(p)] +=1
129+
accumulator[theta+180][p] +=1
124130

125131

126132

@@ -136,7 +142,7 @@ def mark_lines(max_theta, max_p, img):
136142
for i in range(h):
137143
# p = x cosθ + y sinθ
138144
# x = (p - y sinθ) / cosθ
139-
j = int((max_p - (i * math.sin(theta_rad))) / math.cos(theta_rad))
145+
j = int(round((max_p - (i * math.sin(theta_rad))) / math.cos(theta_rad)))
140146
if j<w and j> -1:
141147
img[i][j] = [0,255,0]
142148
return img
@@ -164,7 +170,7 @@ def main():
164170

165171
diagonal_length = math.ceil(math.sqrt(h**2 + w**2))
166172

167-
accumulator = np.zeros([360,diagonal_length*2])
173+
accumulator = np.zeros([360,diagonal_length])
168174

169175
for i in range(h):
170176
for j in range(w):
@@ -173,7 +179,7 @@ def main():
173179

174180

175181

176-
write_image(accumulator,'output/accumulator')
182+
write_image(accumulator,'output/accumulator_line')
177183

178184

179185
hough_img = cv2.imread("original_imgs/hough.jpg")
@@ -192,7 +198,7 @@ def main():
192198

193199

194200
hough_img_blue = hough_img.copy()
195-
co_p_t = np.unravel_index(np.argsort(accumulator.ravel())[-3500:], accumulator.shape)
201+
co_p_t = np.unravel_index(np.argsort(accumulator.ravel())[-2800:], accumulator.shape)
196202

197203
for z in range(len(co_p_t[0])):
198204
max_theta = co_p_t[0][z]-180

0 commit comments

Comments
 (0)