def _label2rgb_avg(label_field, image, bg_label=0, bg_color=(0, 0, 0)):
 out = np.zeros_like(image)
 labels = np.unique(label_field)
 bg = (labels == bg_label)
 if bg.any():
  labels = labels[(labels != bg_label)]
  out[bg] = bg_color
 for label in labels:
  mask = (label_field == label).nonzero()
  color = image[mask].mean(axis=0)
  out[mask] = color
 return out

def _label2rgb_avg ( label_field , image , bg_label = 0 , bg_color = ( 0 , 0 , 0 ) ) : out = np . zeros_like ( image ) labels = np . unique ( label_field ) bg = ( labels == bg_label ) if bg . any ( ) : labels = labels [ ( labels != bg_label ) ] out [ bg ] = bg_color for label in labels : mask = ( label_field == label ) . nonzero ( ) color = image [ mask ] . mean ( axis = 0 ) out [ mask ] = color return out
visualise each segment in label_field with its mean color in image .