How to convert RGB to hsv?
조회 수: 5 (최근 30일)
이전 댓글 표시
댓글 수: 0
답변 (3개)
KALYAN ACHARJYA
2019년 6월 16일
편집: KALYAN ACHARJYA
2019년 6월 16일
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
Walter Roberson
2019년 6월 16일
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
Walter Roberson
2019년 6월 16일
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
2019년 6월 16일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!