Hi,

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);

end

end

% ------- 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));

end

end

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) -

V(m,n))];

end

end

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

V = uint8(V);

return;