Skip to content

Instantly share code, notes, and snippets.

@MaddoxRauch
Last active February 8, 2022 02:49
Show Gist options
  • Save MaddoxRauch/ab18934c3fb620cb938ea9570eff0ecc to your computer and use it in GitHub Desktop.
Save MaddoxRauch/ab18934c3fb620cb938ea9570eff0ecc to your computer and use it in GitHub Desktop.
import cv2
def img_show_components(labels): # Shows the different marks by assigning random colors to them.
# Map component labels to hue val
label_hue = np.uint8(179*labels/np.max(labels))
blank_ch = 255*np.ones_like(label_hue)
labeled_img = cv2.merge([label_hue, blank_ch, blank_ch])
# cvt to BGR for display
labeled_img = cv2.cvtColor(labeled_img, cv2.COLOR_HSV2BGR)
# set bg label to black
labeled_img[label_hue == 0] = 0
cv2.imshow('labeled.png', labeled_img)
cv2.waitKey()
img_show_components(markers)
Use to reveal separated components or markers in cv2 image edits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment