RGB to HSI Color Space Conversion with MATLAB Implementation

Resource Overview

A MATLAB function demonstrating the algorithm for converting between RGB and HSI color spaces, including detailed explanations of intensity, saturation, and hue calculations.

Detailed Documentation

The following MATLAB code implements the conversion from RGB color space to HSI color space: function hsi = rgb_to_hsi(rgb) % Extract RGB components from input vector r = rgb(1); g = rgb(2); b = rgb(3); % Calculate intensity component - average of RGB values intensity = (r + g + b) / 3; % Compute saturation using minimum RGB value normalization saturation = 1 - (3 / (r + g + b)) * min([r, g, b]); % Calculate hue using trigonometric approach based on RGB differences hue = acos((0.5 * ((r - g) + (r - b))) / sqrt((r - g)^2 + (r - b) * (g - b))); % Adjust hue for blue-dominant colors (when blue > green) if b > g hue = 2 * pi - hue; end % Combine components into HSI color vector hsi = [hue, saturation, intensity]; end This code implements the mathematical transformation from RGB to HSI color space through three key calculations: 1. Intensity: Computed as the arithmetic mean of RGB values, representing the overall brightness 2. Saturation: Derived from the minimum RGB value, indicating color purity 3. Hue: Calculated using inverse cosine function with quadrant adjustment for blue-dominated colors The algorithm handles the color space conversion by separating color information (hue and saturation) from intensity information, which is particularly useful in image processing applications where illumination changes need to be decoupled from color information. The function accepts RGB values in the range [0,1] and returns HSI values with hue in radians [0,2π], and saturation/intensity in [0,1] range. Note: For practical implementation, ensure input RGB values are normalized and add error checking for division by zero when (r+g+b) approaches zero.