To perform the color conversion between RGB, BGR, HSV, and YCbCr color models.
Anaconda - Python 3.7
Import cv2 library.
Use cv2.cvtcolor() to convert color in required image.
Use .imshow() to display and .imwrite() to save.
Use split() to disperse color into separate channels.
Use merge() to combine those separate channels into color.
Developed By: Mohan Raj S
Register Number: 212221230065
import cv2
image = cv2.imread('bike.jpg')
cv2.imshow('Original image - Mohan Raj S 212221230065',image)
#BGR2HSV
hsv_image = cv2.cvtColor(image,cv2.COLOR_BGR2HSV)
cv2.imshow('BGR2HSV',hsv_image)
#RGB2HSV
hsv_image1 = cv2.cvtColor(image,cv2.COLOR_RGB2HSV)
cv2.imshow('RGB2HSV',hsv_image1)
#BGR2Gray
gray_image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
cv2.imshow('BGR2GRAY',gray_image)
#RGB2Gray
gray_image1 = cv2.cvtColor(image,cv2.COLOR_RGB2GRAY)
cv2.imshow('RGB2GRAY',gray_image1)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
image = cv2.imread('bike.jpg')
#HSV to RGB
RGB_image = cv2.cvtColor(image,cv2.COLOR_HSV2RGB)
cv2.imshow('HSV to RGB',RGB_image)
#HSV to BGR
BGR_image = cv2.cvtColor(image,cv2.COLOR_HSV2BGR)
cv2.imshow('HSV to BGR',BGR_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
image = cv2.imread('bike.jpg')
#RGB to YCrCb
YCrCb_image = cv2.cvtColor(image,cv2.COLOR_RGB2YCrCb)
cv2.imshow('RGB to YCrCb',YCrCb_image)
#BGR to YCrCb
YCrCb_image = cv2.cvtColor(image,cv2.COLOR_BGR2YCrCb)
cv2.imshow('BGR to YCrCb',YCrCb_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
image = cv2.imread('bike.jpg')
blue = image[:,:,0]
green = image[:,:,1]
red = image[:,:,2]
cv2.imshow('Blue',blue)
cv2.imshow('Green',green)
cv2.imshow('Red',red)
merge=cv2.merge((blue,green,red))
cv2.imshow('Merged Image',merge)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
image = cv2.imread('bike.jpg')
hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
h,s,v = cv2.split(hsv)
cv2.imshow('Hue',h)
cv2.imshow('Saturation',s)
cv2.imshow('Value',v)
merged_HSV = cv2.merge((h,s,v))
cv2.imshow('Merged HSV Image',merged_HSV)
cv2.waitKey(0)
cv2.destoryAllWindows()
Thus the color conversion was performed between RGB, HSV and YCbCr color models.