1
$\begingroup$

I ran some code in matlab to show what is hue, saturation and intensity to get an intuition of what they mean. But the result of the code does not match the explanation i got from here

Hue is a color attribute that describes a pure color (yellow, orange, or red).

Saturation gives a measure of the degree to which a pure color is diluted by white light.

Brightness depends upon color intensity, which is key factor in describing color sensation. The intensity is easily measurable and the results are also easily interpretable.

I=imread("Colorful.jpg")
I2=rgb2hsi(I)

hue=I2(:,:,1);
saturation=I2(:,:,2);
intensity=I2(:,:,3);

figure
subplot(2,3,1)
imshow(I)
title('rgb')
subplot(2,3,2)
imshow(I2)
title('hsi')
subplot(2,3,4)
imshow(hue)
title('hue')
subplot(2,3,5)
imshow(saturation)
title('saturation')
subplot(2,3,6)
imshow(intensity)
title('intensity')

rgb2hsi function:

function hsi = rgb2hsi(rgb)
%RGB2HSI Converts an RGB image to HSI.
% HSI = RGB2HSI(RGB) converts an RGB image to HSI. The input image
% is assumed to be of size M-by-N-by-3, where the third dimension
% accounts for three image planes: red, green, and blue, in that
% order. If all RGB component images are equal, the HSI conversion
% is undefined. The input image can be of class double (with values
% in the range [0, 1]), uint8, or uint16. 
%
% The output image, HSI, is of class double, where:
% hsi(:, :, 1) = hue image normalized to the range [0, 1] by
% dividing all angle values by 2*pi. 
% hsi(:, :, 2) = saturation image, in the range [0, 1].
% hsi(:, :, 3) = intensity image, in the range [0, 1].
% Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins
% Digital Image Processing Using MATLAB, Prentice-Hall, 2004
% $Revision: 1.5 $ $Date: 2005/01/18 13:44:59 $
% Extract the individual component images.
rgb = im2double(rgb);
r = rgb(:, :, 1);
g = rgb(:, :, 2);
b = rgb(:, :, 3);
% Implement the conversion equations.
num = 0.5*((r - g) + (r - b));
den = sqrt((r - g).^2 + (r - b).*(g - b));
theta = acos(num./(den + eps));
H = theta;
H(b > g) = 2*pi - H(b > g);
H = H/(2*pi);
num = min(min(r, g), b);
den = r + g + b;
den(den == 0) = eps;
S = 1 - 3.* num./den;
H(S == 0) = 0;
I = (r + g + b)/3;
% Combine all three results into an hsi image.
hsi = cat(3, H, S, I);
imshow(hsi)

enter image description here

Shouldn't the hue be showing the primary colours instead of black, grays and white? What do the saturation and intensity pictures are showing?

$\endgroup$
2

1 Answer 1

3
$\begingroup$

To display a color image, each pixel needs to have those three values: Red, Green, and Blue. Sometimes there is a fourth, Alpha, channel, but let's ignore that for this question.

What you're seeing in the imshow(I2) plot is that the Hue value is set to Red, the Saturation value is set to Green, and the Intensity (Brightness or Value, sometimes) is set to the Blue channel. That makes the image displayed look to have very different colors from the original image.

Matlab assumes RGB channels, but you've given it different values.

The bottom three images are just showing one channel: instead of an $M \times N \times 3$ matrix, you're giving it an $M \times N \times 1$ matrix. Matlab still tries to display the RGB values, but decides that each channel is equal and so only shows grayscale values.

As is clear from the bottom-left picture, the Hue channel, each number in the Hue channel represents a different "color". So the blue patch looks different from the pink patch which is, again, different from the green/yellow patch.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.