Modules / Computer Vision / RGB Processing

RGB Image Logic

Draw with colors to understand how images are composed of Red, Green, and Blue channels.

Pixel Matrix Breakdown

LIVE CHANNELS

Understanding RGB Image Processing

A deep dive into how digital color is represented and manipulated. Read this, experiment with the tool, and solidify your understanding.

Quick Context

RGB Image Processing is a fundamental concept in computer vision. It's the basis for how computers "see" and manipulate color images. Every colored pixel on your screen is a combination of three values: Red, Green, and Blue.

The Core Idea: Channels as Layers

Think of a color image not as a single flat picture, but as three separate grayscale images stacked on top of each other. Each of these "layers" is a channel, representing the intensity of Red, Green, or Blue light for every pixel.

  • The Red Channel shows where the image is most red.
  • The Green Channel shows where it's most green.
  • The Blue Channel shows where it's most blue.

When combined, their values mix to create the full spectrum of colors we see. A value of (0, 0, 0) is black, (255, 255, 255) is white, and (255, 0, 0) is pure red.

Guided Experiments with This Interactive

Use the tool above to build a strong mental model. Follow these steps:

  1. Draw a Pure Color:
    • Set the brush to pure red (`#FF0000`). Draw a line.
    • Now, switch the "Pixel Matrix Breakdown" to the Red Channel. You'll see high values (like 255).
    • Switch to the Green and Blue channels. They will show values of 0. This proves the color is purely red.
  2. Create a Mixed Color:
    • Clear the canvas. Select a yellow color (`#FFFF00`). Draw something.
    • Check the channels. The Red and Green channels will have high values, while the Blue channel will be 0. This is because yellow is an equal mix of red and green light.
  3. Understand Grayscale Conversion:
    • Draw a colorful image. Then, click the "Convert Grayscale" button.
    • Notice how the image loses its color. Now, inspect the channels. The Red, Green, and Blue channels are now identical! A grayscale image is simply an RGB image where R=G=B for every pixel.
  4. Explore Inversion:
    • Draw a green (`#00FF00`) shape. Click "Invert Colors". The shape turns magenta.
    • Why? The original pixel was (R:0, G:255, B:0). The inverted pixel is (R:255-0, G:255-255, B:255-0), which results in (R:255, G:0, B:255) — the color magenta.

Thinking in Pseudocode

When a computer applies a filter, it iterates through every pixel and applies a mathematical rule. For a brightness adjustment, it looks like this:

function adjust_brightness(image, factor):
  for each pixel (x, y) in image:
    original_color = image.get_pixel(x, y) // e.g., (R:50, G:100, B:200)
    
    new_R = original_color.R * factor
    new_G = original_color.G * factor
    new_B = original_color.B * factor
    
    // Clamp values to stay within the 0-255 range
    new_R = min(255, new_R)
    new_G = min(255, new_G)
    new_B = min(255, new_B)
    
    image.set_pixel(x, y, (new_R, new_G, new_B))
  
  return image

This is exactly what happens when you use the "Brightness" slider and click "Apply".

Common Mistakes & Pitfalls

  • Confusing Additive vs. Subtractive Color: Digital color is additive (mixing light). Adding R, G, and B makes white. This is the opposite of mixing paint (subtractive color), where mixing colors makes black.
  • Ignoring Data Types: Pixel values are almost always stored as 8-bit unsigned integers (0-255). If an operation results in a value like 300 or -50, it must be "clamped" to 255 or 0, respectively. Forgetting this leads to visual artifacts.
  • Thinking Filters "See" Objects: A blur or brightness filter doesn't know it's looking at a car or a face. It's just a simple mathematical rule applied to a grid of numbers. The "intelligence" of computer vision comes from more complex models that learn patterns from these numbers.

Key Takeaways

  • A color image is a 3D array of numbers: `(Height x Width x 3)`.
  • The three layers are the Red, Green, and Blue channels.
  • Image processing operations are just mathematical functions applied to the numerical values of pixels.
  • By isolating and observing the channels, you can understand exactly how any color or filter works.
Cheat sheet

RGB Image Processing

RGB Image Processing is a fundamental concept in computer vision. It's the basis for how computers "see" and manipulate color images. Every colored pixel on your screen is a combination of three values: Red, Green, and Blue.

COMPUTER VISION · vizlearn.in/computer_vision/rgb_image_processing.html