RGB colours are not efficient in their storage, so we often convert images into YCrCb, where Y is the lumosity, and Cb is the blueness, and Cr the redness
RGB Conversion |
Theory
Coding
The following is an outline of the coding. The first argument is the name of the file to process, and the red image is stored with a "0" at the start, the green one with a "1", and the bloue one with a "2" at the start of the file name:
import cv2 import sys imfile = 'http://img.sxsw.com/2015/films/F52361.jpg' file='111.jpg' if (len(sys.argv)>1): imfile=str(sys.argv[1]) def split_into_rgb_channels(image): red = image[:,:,2] green = image[:,:,1] blue = image[:,:,0] return red, green, blue img = cv2.imread(imfile) r,g,b= split_into_rgb_channels(img) im = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) file1 = file cv2.imwrite(file1,im) r,g,b=split_into_rgb_channels(img) file1 = "0"+file cv2.imwrite(file1,r) file1 = "1"+file cv2.imwrite(file1,g) file1 = "2"+file cv2.imwrite(file1,b)