How to convert RGB to hsv?

조회 수: 5 (최근 30일)
Fredrick  Graham
Fredrick Graham 2019년 6월 16일
편집: Fredrick Graham 2019년 6월 17일
I have a RGB data with each size like R is 1 x 100 double. how can i convert these RGB to hsv. I find the formula for it from Wikipedia and it available at [here]:
I also found some materials that could answer my questions such as 1 but it is in another language than Matlab.

답변 (3개)

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

Walter Roberson
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
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]);
Fredrick  Graham
Fredrick Graham 2019년 6월 16일
Thanks

댓글을 달려면 로그인하십시오.


Image Analyst
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;

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by