Giter Club home page Giter Club logo

color-conversion's Introduction

COLOR-CONVERSION

AIM

To perform the color conversion between RGB, BGR, HSV, and YCbCr color models.

Software Required:

Anaconda - Python 3.7

Algorithm:

Step1:

Import opencv.

Step2:

Read the original Image.

Step3:

Store the required conversion of the image in a variable.

Step4:

Show the image stored in the given variable.

Step5:

Destroy all the windows and end the program.

Program:

# Developed By: Dharini PV
# Register Number: 212222240024

i) Convert BGR and RGB to HSV and GRAY

import cv2
houseImage = cv2.imread('car.jpg')
cv2.imshow('212222240024_DhariniPV',houseImage)
hsvImage = cv2.cvtColor(houseImage,cv2.COLOR_BGR2HSV)
cv2.imshow('BGR2HSV',hsvImage)
hsvImage1=cv2.cvtColor(houseImage,cv2.COLOR_RGB2HSV)
cv2.imshow('RGB2HSV',hsvImage1)
grayImage = cv2.cvtColor(houseImage,cv2.COLOR_BGR2GRAY)
cv2.imshow('BGR2GRAY',grayImage)
grayImage1 = cv2.cvtColor(houseImage,cv2.COLOR_RGB2GRAY)
cv2.imshow('RGB2GRAY',grayImage1)
cv2.waitKey(0)
cv2.destroyAllWindows()

ii)Convert HSV to RGB and BGR

import cv2
houseHSVImage = cv2.imread('car.jpg')
cv2.imshow('212222240024_DhariniPV',houseHSVImage)
RGBImage = cv2.cvtColor(houseHSVImage,cv2.COLOR_HSV2RGB)
cv2.imshow('BGR2HSV',RGBImage)
BGRImage=cv2.cvtColor(houseHSVImage,cv2.COLOR_HSV2BGR)
cv2.imshow('RGB2HSV',BGRImage)
cv2.waitKey(0)
cv2.destroyAllWindows()

iii)Convert RGB and BGR to YCrCb

import cv2
houseImage = cv2.imread('car.jpg')
cv2.imshow('212222240024_DhariniPV',houseImage)
YCrCb_image = cv2.cvtColor(houseImage, cv2.COLOR_RGB2YCrCb)
cv2.imshow('BGR2HSV',YCrCb_image)
YCrCb_image1 = cv2.cvtColor(houseImage, cv2.COLOR_BGR2YCrCb)
cv2.imshow('RGB2HSV',YCrCb_image1)
cv2.waitKey(0)
cv2.destroyAllWindows()

iv)Split and Merge RGB Image

import cv2
image = cv2.imread('car.jpg')
blue = image[:,:,0]
green = image[:,:,1]
red = image[:,:,2]
cv2.imshow('B-Channel',blue)
cv2.imshow('G-Channel',green)
cv2.imshow('R-Channel',red)
mergeBgr = cv2.merge((blue,green,red))
cv2.imshow('Merged BGR image',mergeBgr)
cv2.waitKey(0)
cv2.destroyAllWindows()

v) Split and merge HSV Image

import cv2
image = cv2.imread('car.jpg')
hsv = cv2.cvtColor(image,cv2.COLOR_BGR2HSV)
h,s,v = cv2.split(hsv)
cv2.imshow('Hue - Image',h)
cv2.imshow('Saturation - Image',s)
cv2.imshow('Gray - Image',v)
mergedHSV = cv2.merge((h,s,v))
cv2.imshow('212222240024_DhariniPV',mergedHSV)
cv2.waitKey(0)
cv2.destroyAllWindow

Output:

i) BGR and RGB to HSV and GRAY

Screenshot from 2023-08-23 18-13-51

ii) HSV to RGB and BGR

Screenshot from 2023-08-23 18-27-35

iii) RGB and BGR to YCrCb

Screenshot from 2023-08-23 18-46-24

iv) Split and merge RGB Image

Screenshot from 2023-08-23 18-38-16

v) Split and merge HSV Image

Screenshot from 2023-08-23 18-53-10

Result:

Thus the color conversion was performed between RGB, HSV and YCbCr color models.

color-conversion's People

Contributors

dharinipv avatar swedha333 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.