How to convert RGB to hsv?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
0 commentaires
Réponses (3)
KALYAN ACHARJYA
le 16 Juin 2019
Modifié(e) : KALYAN ACHARJYA
le 16 Juin 2019
For one frame, you can check here, as you mentioned the reference (wiki), I have implmented the same from here
I assumed, you can find R,G,B
Defining hue in terms of RGB
hue_rgb=atan2(sqrt(3)*(G-B),R-G-B)
0 commentaires
Walter Roberson
le 16 Juin 2019
for H = 1:ncols
if T3(H) == 0
hprime(H) = 0;
elseif T1(H) == R(H)
hprime(H) = mod((G(H)-B(H))/C(H), 6);
elseif T1(H) == G(H)
hprime(H) = ((B(H)-R(H))/C(H))+2;
elseif T1(H) == B(H)
hprime(H) = ((R(H)-G(H))/C(H))+4;
else
error('undefined hue at index %d', H);
end
end
6 commentaires
Walter Roberson
le 16 Juin 2019
What difficulty did you run into with the code that I had already posted to take care of the issue?
T1 = max([R; G; B]);
Image Analyst
le 16 Juin 2019
Why not simply use the built-in rgb2hsv() function:
% load R and G and B data
clear
close all
clc
load('RGB.mat')
subplot(4,1,1)
plot(t,R,'r')
ylim([110, 160]);
xlabel('Time (sec)')
ylabel('Red')
grid on;
subplot(4,1,2)
plot(t,G,'g')
ylim([110, 160]);
xlabel('Time (sec)')
ylabel('Green')
grid on;
subplot(4,1,3)
plot(t,B,'b')
ylim([110, 160]);
xlabel('Time (sec)')
ylabel('Blue')
grid on;
% Convert RGB to HSV:
RGBMatrix = [R; G; B];
% Make MxNx3 array rather than a Mx3 array (where rgb2hsv will think it's a colormap rather than a list of RGB values).
RGBMatrix = repmat(RGBMatrix, [1, 1, 2]);
RGBMatrix = permute(RGBMatrix, [3, 2, 1]);
hsvVec = rgb2hsv(RGBMatrix);
hueVector = hsvVec(1, :, 1);
subplot(4,1,4)
plot(t,hueVector,'b')
xlabel('Time (sec)')
ylabel('Hue')
grid on;
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!