Showing posts with label RGB. Show all posts
Showing posts with label RGB. Show all posts

Wednesday, October 30, 2024

Color Spaces in Computer Vision: RGB, CMYK, XYZ, and HSV


Color Spaces in Computer Vision – RGB, CMYK, XYZ, HSV Explained

๐ŸŽจ Color Spaces in Computer Vision (Simple + Deep Explanation)

Computers do not “see” color like humans. Instead, they store color as numbers inside structured systems called color spaces.

This guide explains RGB, CMYK, XYZ, and HSV in a simple and intuitive way with math where needed.


๐Ÿ“š Table of Contents


๐Ÿง  What is a Color Space?

A color space is a system that maps colors into numbers.

Think of it like GPS for colors: Instead of latitude/longitude → we use numerical coordinates for color.

Each color space has its own coordinate system.


๐Ÿ”ด 1. RGB (Red, Green, Blue)

RGB is the most common color model used in screens.

How it works

Each pixel is represented as:

\[ RGB = (R, G, B) \]

Where each value ranges from 0 to 255.

Examples

  • (255, 0, 0) → Red
  • (0, 255, 0) → Green
  • (0, 0, 255) → Blue
  • (255, 255, 255) → White
  • (0, 0, 0) → Black

Intuition

RGB = adding light (like mixing colored lights in a dark room)

๐Ÿ–จ️ 2. CMYK (Cyan, Magenta, Yellow, Black)

Used in printing systems.

How it works

\[ CMYK = (C, M, Y, K) \]

Values are usually between 0 and 1.

Key idea

CMYK works by subtracting light, not adding it.

White paper = full light Ink = reduces reflected light

Why black (K)?

Mixing C + M + Y does NOT produce perfect black → it produces muddy brown. So black ink is added separately.


๐ŸŒ 3. XYZ Color Space (CIE 1931)

This is a scientific color model based on human vision.

How it works

\[ XYZ = (X, Y, Z) \]

  • X → mix of red/green sensitivity
  • Y → brightness (luminance)
  • Z → blue sensitivity

Important idea

XYZ is not for display—it is a reference standard.

It acts as a bridge between RGB and CMYK.


๐ŸŒˆ 4. HSV (Hue, Saturation, Value)

HSV is very intuitive for humans and used in image processing.

How it works

\[ HSV = (H, S, V) \]

  • Hue (H) → color type (0°–360°)
  • Saturation (S) → intensity of color
  • Value (V) → brightness

Examples

  • (0°, 100%, 100%) → Red
  • (120°, 100%, 100%) → Green
  • (240°, 100%, 100%) → Blue

Why it is useful

HSV separates “color” from “brightness” → very useful in object detection

๐Ÿ“ Math Behind Color Spaces (Simple Explanation)

1. RGB to Gray Conversion

\[ Gray = 0.299R + 0.587G + 0.114B \]

Explanation:

  • Green contributes most to brightness (our eyes are sensitive to it)
  • Blue contributes least

2. Normalization

\[ R' = \frac{R}{255}, \quad G' = \frac{G}{255}, \quad B' = \frac{B}{255} \]

Why normalize?

It scales values to 0–1 so math becomes stable in ML models.

3. HSV Hue Calculation (Idea)

Hue depends on which channel (R, G, B) is maximum and the difference between them.


๐Ÿ“Š Comparison Table

Color Space Use Case Strength
RGB Screens Simple, hardware-based
CMYK Printing Ink-based accuracy
XYZ Color science Universal standard
HSV Image processing Human-friendly

๐Ÿง  Why Color Spaces Matter in Computer Vision

  • Object detection works better in HSV
  • Image segmentation relies on color separation
  • Printing requires CMYK conversion
  • Deep learning often normalizes RGB
Choosing the wrong color space = harder model performance

๐Ÿ’ก Key Takeaways

  • Color spaces are just different ways to represent color numerically
  • RGB is for screens
  • CMYK is for printing
  • XYZ is a scientific reference system
  • HSV is best for computer vision tasks

๐ŸŽฏ Final Thought

Color is not just visual—it is mathematical. Understanding color spaces helps you build better computer vision systems, from filters to deep learning models.

Every image you see on a screen is just numbers carefully translated into light.

Featured Post

How HMT Watches Lost the Time: A Deep Dive into Disruptive Innovation Blindness in Indian Manufacturing

The Rise and Fall of HMT Watches: A Story of Brand Dominance and Disruptive Innovation Blindness The Rise and Fal...

Popular Posts