Last active
February 28, 2020 04:48
-
-
Save clpud/ce8a276856ab2852492c316a839c745c to your computer and use it in GitHub Desktop.
Calculate LAB Mean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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