To perform the color conversion between RGB, BGR, HSV, and YCbCr color models.
Anaconda - Python 3.7
Import cv2 library and upload the image or capture an image.
Read the saved image using cv2.imread("filename.jpg").
Convert the image into the given color transformation using cv2.cvtColor(image, cv2.BGR2YCrCb) and similarly for other color formats.
Split and merge the image using cv2.split(hsv) and cv2.merge([h,s,v])
Output the image using cv2.imshow("OUTPUT", image)
Developed By: Shafeeq Ahamed. S
Register Number: 212221230092
img = cv2.imread('Mikasa.jpeg')
cv2.imshow('original',img)
bgr2hsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
cv2.imshow('BGR To HSV',bgr2hsv)
bgr2gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.imshow('BGR To GRAY',bgr2gray)
rgb2hsv = cv2.cvtColor(img_rgb,cv2.COLOR_RGB2HSV)
cv2.imshow('RGB2HSV',rgb2hsv)
rgb2gray = cv2.cvtColor(img_rgb,cv2.COLOR_RGB2GRAY)
cv2.imshow('RGB2GRAY',rgb2gray)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imshow('HSV',bgr2hsv)
hsv2rgb = cv2.cvtColor(bgr2hsv,cv2.COLOR_HSV2RGB)
cv2.imshow('HSVtoRGB',hsv2rgb)
hsv2bgr = cv2.cvtColor(bgr2hsv,cv2.COLOR_HSV2BGR)
cv2.imshow('HSVtoBGR',hsv2bgr)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imshow('RGB',img_rgb)
rgb2YcrCb = cv2.cvtColor(img_rgb,cv2.COLOR_RGB2YCrCb)
cv2.imshow('RGBtoYCrCb',rgb2YcrCb)
bgr2YcrCb = cv2.cvtColor(img,cv2.COLOR_HSV2BGR)
cv2.imshow('BGRtoYCrCb',bgr2YcrCb)
cv2.waitKey(0)
cv2.destroyAllWindows()
b,g,r = cv2.split(img)
cv2.imshow("RED MODEL", r)
cv2.imshow("GREEN MODEL", g)
cv2.imshow("BLUE MODEL ", b)
merger = cv2.merge([b,g,r])
cv2.imshow("MERGED IMAGE", merger)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imshow("INITIAL_HSV ", bgr2hsv)
h,s,v = cv2.split(bgr2hsv)
cv2.imshow("RED MODEL", h)
cv2.imshow("GREEN MODEL", s)
cv2.imshow("BLUE MODEL ", v)
merger = cv2.merge([h,s,v])
cv2.imshow("MERGED IMAGE", merger)
cv2.waitKey(0)
cv2.destroyAllWindows()
Original - BGR | BGR to HSV | BGR to GRAY |
---|---|---|
![]() |
![]() |
![]() |
Original - RGB | RGB to HSV | RGB to GRAY |
---|---|---|
![]() |
![]() |
![]() |
Original - HSV | HSV to RGB | HSV to BGR |
---|---|---|
![]() |
![]() |
![]() |
Original - RGB | RGB to YCrCb |
---|---|
![]() |
![]() |
Original - BGR | BGR to YCrCb |
---|---|
![]() |
![]() |
RED Component | GREEN Component | BLUE Component | MERGED Image |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
HUE Component | SATURATION Component | VALUE Component | MERGED Image |
---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Thus the color conversion was performed between RGB, HSV and YCbCr color models.