pamixsun commited on
Commit
a7773b0
1 Parent(s): dfbd972

Create utils.py

Browse files
Files changed (1) hide show
  1. utils.py +44 -0
utils.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import numpy as np
3
+
4
+
5
+ def add_mask(image, label, vis_labels, colors, alpha=0.5):
6
+
7
+ if len(image.shape) < 3 or image.shape[2] == 1:
8
+ image = image.repeat(3).reshape((image.shape[0], image.shape[1], 3)).astype(np.uint8)
9
+ ori_image = image.copy()
10
+
11
+ for ci, vis_label in enumerate(vis_labels):
12
+ color = colors[ci]
13
+ mask = label == vis_label
14
+ for i in range(3):
15
+ image[:, :, i][mask] = (color[i] * alpha + image[:, :, i][mask] * (1 - alpha)).astype(np.uint8)
16
+
17
+ return ori_image, image
18
+
19
+
20
+ def find_haight(mask):
21
+ v_sum = (np.sum(mask, axis=1) > 0).astype(np.uint8)
22
+
23
+ v_diff = np.diff(np.hstack((0, v_sum, 0)))
24
+
25
+ v_min_y = np.where(v_diff > 0)[0][0]
26
+ v_max_y = np.where(v_diff < 0)[0][-1] - 1
27
+
28
+ return v_max_y - v_min_y
29
+
30
+
31
+ def simple_vcdr(mask):
32
+
33
+ disc_mask = (mask > 0).astype(np.uint8)
34
+ disc_height = find_haight(disc_mask)
35
+
36
+ cup_mask = (mask > 1).astype(np.uint8)
37
+ cup_height = find_haight(cup_mask)
38
+
39
+ vcdr = cup_height / disc_height
40
+
41
+ return vcdr
42
+
43
+
44
+