Created
October 23, 2017 01:29
-
-
Save nhomble/68ddf4fc7f1628319d0be694fb8a5234 to your computer and use it in GitHub Desktop.
show lab color space
This file contains 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 thresh(src, img, low, ty): | |
_, mask = cv2.threshold(img, low, 256, ty) | |
splits = [cv2.bitwise_and(x, mask) for x in cv2.split(src)] | |
return cv2.merge(splits) | |
img = cv2.imread("rubiks.png") | |
lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB) | |
grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
[l, a, b] = cv2.split(lab) | |
def f(img): | |
return cv2.resize(img, (200, 200)) | |
while True: | |
cv2.imshow("bgr", f(img)) | |
cv2.imshow("grey", f(grey)) | |
cv2.imshow("b max", f(thresh(img, b, b.max()-10, cv2.THRESH_BINARY))) | |
cv2.imshow("a max", f(thresh(img, a, a.max()-10, cv2.THRESH_BINARY))) | |
cv2.imshow("b min", f(thresh(img, b, a.min() + 10, cv2.THRESH_BINARY_INV))) | |
cv2.imshow("a min", f(thresh(img, a, b.min() + 10, cv2.THRESH_BINARY_INV))) | |
cv2.imshow("L", f(l)) | |
cv2.imshow("a", f(a)) | |
cv2.imshow("b", f(b)) | |
if cv2.waitKey(1) == ord('q'): | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment