In image processing, color spaces are essential for standardizing the specification of colors.
Various color models are employed across different fields, such as hardware design and animation creation.
Let’s explore each color model and its application:
RGB CMYK HSV YIQ
RGB: The RGB color model is the most prevalent model used in digital image processing and OpenCV. A color image in this model consists of three channels: one for each primary color—Red, Green, and Blue. All other colors are created through varying proportions of these three colors. A value of 0 represents black, and as the value increases, the color intensity increases.
Properties:
- It is an additive color model, where colors are added to black.
- It has three main channels: Red, Green, and Blue.
- It is used in digital image processing, OpenCV, and online logos.

Colour combination: Green(255) + Red(255) = Yellow Green(255) + Blue(255) = Cyan Red(255) + Blue(255) = Magenta Red(255) + Green(255) + Blue(255) = White
CMYK Color Model
The CMYK color model is extensively used in the printing industry. The acronym CMYK stands for Cyan, Magenta, Yellow, and Key (Black). Unlike the RGB model, which is additive, the CMYK model is subtractive. This means it works by subtracting varying degrees of light absorbed by the colors.
In the CMYK model:
- 0 represents the primary color at its full intensity.
- 1 represents the absence of color, resulting in white.
For example, the point (1, 1, 1) signifies black, while the point (0, 0, 0) signifies white. As a subtractive model, the color values are subtracted from 1 to range from the least intense (lightest) to the most intense (darkest) color values.
A critical relationship between the RGB and CMYK models is given by:
1 – RGB=CMY\text{1 – RGB} = \text{CMY}1 – RGB=CMY
This means:
- Cyan is the negative of Red.
- Magenta is the negative of Green.
- Yellow is the negative of Blue.
Understanding this relationship helps in converting between the RGB and CMYK models, which is particularly useful in ensuring color consistency across digital displays (which use RGB) and printed media (which uses CMYK).

HSV Color Model
The HSV color model represents colors through three channels: Hue, Saturation, and Value. Unlike models that directly use primary colors, HSV aligns with how humans perceive color. The HSV model is often depicted as a cone.

Hue is the color component, representing different colors based on angle ranges within the HSV cone:
- Red falls between 0 and 60 degrees.
- Yellow falls between 61 and 120 degrees.
- Green falls between 121 and 180 degrees.
- Cyan falls between 181 and 240 degrees.
- Blue falls between 241 and 300 degrees.
- Magenta falls between 301 and 360 degrees.
Saturation describes the purity of the color, ranging from 0 to 1. A saturation of 0 results in a shade of gray, while a saturation of 1 corresponds to a fully saturated color. This parameter helps determine the amount of gray in the color.
Value indicates the brightness or intensity of the color, ranging from 0% to 100%. A value of 0% represents black, while a value of 100% represents the brightest form of the color. The higher the value, the more vivid and intense the color appears.
In summary, the HSV model offers an intuitive way to understand and manipulate colors based on human perception, making it particularly useful in various applications like graphic design and image processing.

There exist a formula to convert RGB into YIQ and vice-versa.

Application in OpenCV
OpenCV (Open Source Computer Vision Library) uses the RGB model extensively for image manipulation and analysis.
import cv2
import numpy as np
# Create an RGB image
image = np.zeros((300, 300, 3), dtype=np.uint8)
# Fill the image with a red color
image[:] = (0, 0, 255) # RGB for red
# Display the image
cv2.imshow("RGB Image", image)
cv2.waitKey(0)
cv2.destroyAllWindows()

In this example, a red image is created using the RGB model in OpenCV.
OpenCV primarily uses the RGB model, but conversion between RGB and CMYK can be performed for printing purposes.
Example:
import cv2
import numpy as np
# Convert RGB to CMYK
def rgb_to_cmyk(r, g, b):
r, g, b = r / 255.0, g / 255.0, b / 255.0
k = 1 - max(r, g, b)
c = (1 - r - k) / (1 - k)
m = (1 - g - k) / (1 - k)
y = (1 - b - k) / (1 - k)
return c, m, y, k
# Convert CMYK to RGB
def cmyk_to_rgb(c, m, y, k):
r = 255 * (1 - c) * (1 - k)
g = 255 * (1 - m) * (1 - k)
b = 255 * (1 - y) * (1 - k)
return r, g, b
# Example usage
r, g, b = 255, 0, 0 # Red color
c, m, y, k = rgb_to_cmyk(r, g, b)
r, g, b = cmyk_to_rgb(c, m, y, k)
OpenCV supports the HSV color model for various tasks like object tracking and color filtering.
import cv2
# Load an image
image = cv2.imread('example.jpg')
# Convert the image from BGR to HSV
hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
# Display the HSV image
cv2.imshow("HSV Image", hsv_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
This example converts an image from BGR (OpenCV’s default) to HSV.
OpenCV can convert images to and from the YIQ color model, although it’s less commonly used compared to RGB and HSV.
import cv2
# Load an image
image = cv2.imread('example.jpg')
# Convert the image from BGR to YIQ
yiq_image = cv2.cvtColor(image, cv2.COLOR_BGR2YCrCb)
# Display the YIQ image
cv2.imshow("YIQ Image", yiq_image)
cv2.waitKey(0)
cv2.destroyAllWindows()

Conclusion
Understanding the differences and applications of various color models like RGB, CMYK, HSV, and YIQ is essential for effective image processing and manipulation. Each model has its unique properties and is suited for different tasks, from digital imaging and printing to broadcasting. You can achieve precise and efficient color management in your projects by leveraging these models in OpenCV. Whether you are developing applications for digital displays, creating print-ready graphics, or performing advanced image analysis, choosing the right color model is key to success.





Leave a Reply