-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcal_diameter.py
35 lines (28 loc) · 918 Bytes
/
cal_diameter.py
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
import os
import numpy as np
from PIL import Image
def make_mask(mask_txt_path):
imgs = []
f_mask = open(mask_txt_path, 'r')
for mask in f_mask:
mask = mask.rstrip()
imgs.append(mask)
f_mask.close()
return imgs
def get_diameter(train_mask_txt_path):
imgs = make_mask(train_mask_txt_path)
diameter = 0
for i, img in enumerate(imgs):
img = Image.open(img)
img = np.array(img)
dim0 = np.max(np.where(img == 128)[0]) - np.min(np.where(img == 128)[0])
dim1 = np.max(np.where(img == 128)[1]) - np.min(np.where(img == 128)[1])
dim_max = dim0 if dim0 > dim1 else dim1
if dim_max > diameter:
diameter = dim_max
print(i)
return diameter
if __name__ == '__main__':
train_mask_txt_path = os.path.join("refuge", "train_mask.txt")
diameter = get_diameter(train_mask_txt_path)
print(diameter)