-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistance_write_single_thread.py
More file actions
48 lines (35 loc) · 1.17 KB
/
distance_write_single_thread.py
File metadata and controls
48 lines (35 loc) · 1.17 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
from skimage.feature import canny
from skimage import img_as_ubyte
import glob
import cv2
import os
import re
canny_sigma = 2.25
def _find_bottom_edge(img_bw):
for i in reversed(xrange(len(img_bw))):
for j in xrange(len(img_bw[0])):
if(img_bw[i][j] > 0):
point = (j, i)
return point
fh = open("distances_sigma_" + str(canny_sigma) + ".txt", "a")
files = glob.glob(os.getcwd() + "/resize150/*")
for input_file_path in files:
int_values = []
path_sections = input_file_path.split("/")
for string in path_sections:
if re.search(r'\d+', string) is not None:
int_values.append(int(re.search(r'\d+', string).group()))
file_count = int_values[-1]
print file_count
image = cv2.imread(input_file_path, cv2.CV_LOAD_IMAGE_GRAYSCALE)
edges = img_as_ubyte(canny(image, sigma=canny_sigma))
img_bw = cv2.threshold(edges, 250, 255, cv2.THRESH_BINARY)[1]
point = _find_bottom_edge(img_bw)
try:
distance = len(img_bw) - point[1]
except TypeError:
distance = 200
output = str(file_count) + ":" + str(distance) + "\n"
fh.write(output)
fh.flush()
fh.close()