Extract RGB Color From a Image Using CV2

1736876797.png

Written by Aayush Saini · 1 minute read · Jun 22, 2020 . Computer Vision, 63

Hi Everyone, We are Come Back with a New Post, In this post, We learn How to Extract RGB Color From an Image. In Simple Language Convert an Image Into Red, Green and Blue Color.

We Use CV2 Library for Extract RGB Color From an Image. There are Few Steps to Extract RGB Color from an Image.

  1. Import Library
  2. Read Image 
  3. Split Image to RGB
  4. Show Image

Necessary Library 

  1. CV2
  2. Numpy
#import library
import cv2
import numpy as np
#Read Image
img = cv2.imread('logo.png')
cv2.imshow('Output Image1', img)
cv2.waitKey(0)
#Split Image
B,G,R = cv2.split(img)
zero = np.zeros(img.shape[:2],dtype ='uint8')
cv2.imshow('Red', cv2.merge([zero,zero,R]))
cv2.waitKey(0)
cv2.imshow('Green', cv2.merge([zero,G,zero]))
cv2.waitKey(0)
cv2.imshow('Blue',cv2.merge([G,zero,zero]))
cv2.waitKey(0)
cv2.destroyAllWindows()
output extract rgb



Download Source Code  

Thanks for Reading Share this  

Share   Share