by nik » Mon, 01 Mar 2010 00:52:03 GMT


I had to build a function that converts RGB to HSV. This is what I've
done so far but I am not sure if it is correct or not. Plus, I am
stuck with Hue conversion.. can someone help me to verify if I am on
the right track or at least give a hint. I've tried to verify it using
the built in function rgb2hsv in matlab, but when I plot it
separately, there was only a blue image appeared. To verify it, this i
did H=rgb2hsv(I); image(H(:,:,1)); image(H(:,:,2)) etc2..

% This function converts RGB truecolor image to HSV
function [H,S,V] = rgbTOhsv(T)

[R C B] = size(T);

% ------ V -------
ro = T(:,:,1);
go = T(:,:,2);
bo = T(:,:,3);

for i = 1:R
for j = 1:C
c(i,j) = ro(i,j) + go(i,j) + bo(i,j);

V(i,j) = (1/3)*c(i,j);

% ------- S -------
for m = 1:R
for n = 1:C
rs(m,n) = double((ro(m,n) - V(m,n))^2);
gs(m,n) = double((go(m,n) - V(m,n))^2);
bs(m,n) = double((bo(m,n) - V(m,n))^2);

S(m,n) = sqrt(rs(m,n) + gs(m,n) + bs(m,n));

S = uint8(S);

% ------- H -------
V = double(V);

for p = 1:R
for q = 1:C
x = V(p,q)*[2; -1; -1];
so = [(ro(m,n) - V(m,n)); (go(m,n) - V(m,n)); (bo(m,n) -

H = acos(dot(double(so),double(x))/(length(so)*length(x)));

V = uint8(V);

Similar Threads

1. Plot Color RGB HSV - MATLAB

2. RGB to HSV

I know there is the function which converses an image from RGB to HSV
color space is rgb2hsv. But is there any function which convert only
one value RGB to HSV?

Thang Nguyen.

3. transform RGB to HSV - MATLAB

4. delphi >>>>> matlab

I'm studying computer & control engineering.I used to program with
delphi. Can I use the Matlab GUIDE to produce a gui application
exactly such as delphi?

5. Convert indexed image -> RGB - MATLAB

6. RGB -> grayscale / jet colormap


I want to transform measured color bitmaps (256x1024x3) to grayscale.
The bitmaps were originaly in grayscale, but were changed by the
measurement software to false colors. It is not possible to access
this color map. The colors contained in the bitmaps are similar (not
exacly same) as the jet colormap in ML. When using standart grayscale
converter, I always achieve a wrong output: red/yellow gives the
highes grayscale value and not red.

Is there a simple tool or routine to do this? Even if it is based on
the jet color map?

thanks in advance

7. Colorspec string -> RGB - MATLAB

8. Replicate matlab>tstool>Select Data Using Rules>Outlier Detection

I am trying to replicate the matlab>tstool>Select Data 
Using Rules>Outlier Detection in an m-file. I have tried 
everything I could think of but, I have not been able to 
replicate the results based on the help description. Is 
anyone aware of an m-file that can replicate the results of 
this function or can expand upon the description of the 
underlying algorithm? If necessary, I can post the data 
series I used and all the methods I have tried.

Thanks in advance for your help