MCPcopy Create free account
hub / github.com/SystemErrorWang/White-box-Cartoonization / label2rgb

Function label2rgb

train_code/utils.py:40–69  ·  view source on GitHub ↗
(label_field, image, kind='mix', bg_label=-1, bg_color=(0, 0, 0))

Source from the content-addressed store, hash-verified

38
39
40def label2rgb(label_field, image, kind='mix', bg_label=-1, bg_color=(0, 0, 0)):
41
42 #std_list = list()
43 out = np.zeros_like(image)
44 labels = np.unique(label_field)
45 bg = (labels == bg_label)
46 if bg.any():
47 labels = labels[labels != bg_label]
48 mask = (label_field == bg_label).nonzero()
49 out[mask] = bg_color
50 for label in labels:
51 mask = (label_field == label).nonzero()
52 #std = np.std(image[mask])
53 #std_list.append(std)
54 if kind == 'avg':
55 color = image[mask].mean(axis=0)
56 elif kind == 'median':
57 color = np.median(image[mask], axis=0)
58 elif kind == 'mix':
59 std = np.std(image[mask])
60 if std < 20:
61 color = image[mask].mean(axis=0)
62 elif 20 < std < 40:
63 mean = image[mask].mean(axis=0)
64 median = np.median(image[mask], axis=0)
65 color = 0.5*mean + 0.5*median
66 elif 40 < std:
67 color = image[mask].median(axis=0)
68 out[mask] = color
69 return out
70
71
72

Callers 1

color_ss_mapFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected