

Using the above code, this RGB image of a plant was converted into CMYK and the four channels split: A RGB image of a plant that will be converted to CMYK and the individual channels split. The code takes a RGB image, converts it to CMYK and splits the channels saving each as a greyscale image. # Convert the input BGR image to CMYK colorspaceĬMYK = (np.dstack((C,M,Y,K)) * 255).astype(np.uint8) With np.errstate(invalid='ignore', divide='ignore'): The numpy, matplotlib and OpenCV (cv2) modules are required for the following example script to work: #!/usr/bin/python The mathematics for the channel conversions from RGB to CMYK are as follows: Each of these channels can be isolated in Python with some relatively simple code. In my work with image analysis, I have found it useful to split and isolate CMYK channels.ĬMYK stands for Cyan, Magenta, Yellow and Key (Black). The CMYK colour model is an additive model frequently used in the commercial printing industry. When conducting analysis of images, it may be useful to separate out individual channels from an image and examine them separately. Efficient Python code for taking a RGB image and converting it to CMYK before splitting the relevant channels out.
