MATLAB >> RGB -> HSV

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

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;

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. <%><%><%><%>HOW TO BE FUNNY!<%><%><%><%> - MATLAB

6. Convert indexed image -> RGB

Hello!

I created an own colormap and display an array with this
colormap:

load('MyColormaps','mycmap')
set(figure,'Colormap',mycmap)
imagesc(BPattern) 

Now, i need this as RGB. Can i get this image from the
figure to RGB?


I tried to convert the array to RGB with:
RGB = ind2rgb(BPattern, mycmap)

But there is only a white or a blue area (depending on the
colormap i use). So it doesn't work like:
set(figure,'Colormap',mycmap)
imagesc(BPattern).

Does somebody know what am doing wrong or if there is
another way to get the array (displayed with my colormap) to
RGB?

All the best,
Maik

7. RGB -> grayscale / jet colormap - MATLAB

8. Colorspec string -> RGB

This must be a simple question. Is there any stock function that converts colorspec strings (short or long) to corresponding RGB values?

Thanks

Bruno