Skip to content

Instantly share code, notes, and snippets.

@clpud
Last active February 28, 2020 04:48
Show Gist options
  • Select an option

  • Save clpud/ce8a276856ab2852492c316a839c745c to your computer and use it in GitHub Desktop.

Select an option

Save clpud/ce8a276856ab2852492c316a839c745c to your computer and use it in GitHub Desktop.
Calculate LAB Mean
import cv2
def calculate_lab_mean(img):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
t, mask = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY)
lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
l, a, b = cv2.mean(lab, mask)[:3]
return l * 100 / 255, a - 128, b - 128
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment