ComputerVision/OpenCV Notes/Notes/Basics/spaces.py
2021-09-26 16:24:06 -04:00

39 lines
1.0 KiB
Python

import cv2 as cv
import matplotlib.pyplot as plt
img = cv.imread('Photos/park.jpg')
cv.imshow('Park', img)
# plt.imshow(img)
# plt.show()
# BGR to Grayscale
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
cv.imshow('Gray', gray)
# BGR to HSV (hue saturation value based on how humans think and conceive of color)
hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)
cv.imshow('HSV', hsv)
# BGR to Lab (or L*a*b)
lab = cv.cvtColor(img, cv.COLOR_BGR2LAB)
cv.imshow('LAB', lab)
# openCV reads in images in a BGR format and that's not the current system we use to represent colors outside of OpenCV (we use RGB)
# BGR to RGB
rgb = cv.cvtColor(img, cv.COLOR_BGR2RGB)
cv.imshow('RGB', rgb)
# HSV to BGR
hsv_bgr = cv.cvtColor(hsv, cv.COLOR_HSV2BGR)
cv.imshow('HSV--> BGR', hsv_bgr)
# LAB to BGR
lab_bgr = cv.cvtColor(lab, cv.COLOR_LAB2BGR)
cv.imshow('LAB--> BGR', lab_bgr)
plt.imshow(rgb) # matplotlib default is rgb (keep in mind of inversion of colors that tends to take place between OpenCV and MatPlotLib libraries)
plt.show()
cv.waitKey(0)