I have a vector of R, G and B signal from a video along with the time of frame capture and each vector size like R
is 1 x 100 double
. I want to generate the Hue from these vectors of RGB signals that I have. I find the formula for it from Wikipedia and it simply looks as follows:
RGB.mat: below is an example of R, G, B,t. Each are vector of 1x800 double, which I only included a 5 here:
R = 12.7 15.7 15.9 15.8 15.7
G= 12.7 12.7 12.7 12.5 12.4
B = 16.4 16.1 16.1 16.0 15.9
t = 0.03 0.06 0.10 0.13 0.16
so, I am very new in Matlab and i tried myself and complete code is:
%% load R and G and B data
load('RGB.mat')
subplot(3,1,1)
plot(t,R,'r')
subplot(3,1,2)
plot(t,G,'g')
subplot(3,1,3)
plot(t,B,'b')
T1 = max([R; G; B]);
T2 = min([R; G; B]);
T3 = T1 -T2
% get hue
%R, G, B are row vectors
ncols = length([R, G, B]);
hprime = zeros(1, ncols);
for H = 1:ncols
if T3(H) == 0
hprime(H) = 0;
elseif T1(H) == R(H)
hprime(H) = mod((G(H)-B(H))/T3(H), 6);
elseif T1(H) == G(H)
hprime(H) = ((B(H)-R(H))/T3(H))+2;
elseif T1(H) == B(H)
hprime(H) = ((R(H)-G(H))/T3(H))+4;
else
error('undefined hue at index %d', H);
end
end
I found some similar post that could answer my questions such as 1 but it is in another language than Matlab. It would be great if you can provide your help with the code that I can also run it on my side as well.