File size: 1,054 Bytes
a7773b0 a504466 a7773b0 |
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 |
import numpy as np
def add_mask(image, label, vis_labels, colors, alpha=0.5):
if len(image.shape) < 3 or image.shape[2] == 1:
image = image.repeat(3).reshape((image.shape[0], image.shape[1], 3)).astype(np.uint8)
ori_image = image.copy()
for ci, vis_label in enumerate(vis_labels):
color = colors[ci]
mask = label == vis_label
for i in range(3):
image[:, :, i][mask] = (color[i] * alpha + image[:, :, i][mask] * (1 - alpha)).astype(np.uint8)
return ori_image, image
def find_haight(mask):
v_sum = (np.sum(mask, axis=1) > 0).astype(np.uint8)
v_diff = np.diff(np.hstack((0, v_sum, 0)))
v_min_y = np.where(v_diff > 0)[0][0]
v_max_y = np.where(v_diff < 0)[0][-1] - 1
return v_max_y - v_min_y
def simple_vcdr(mask):
disc_mask = (mask > 0).astype(np.uint8)
disc_height = find_haight(disc_mask)
cup_mask = (mask > 1).astype(np.uint8)
cup_height = find_haight(cup_mask)
vcdr = cup_height / disc_height
return vcdr
|