Undefined function or variable
5 次查看(过去 30 天)
显示 更早的评论
hi i am trying to make my own rgb-to-hsv function. this is my code.
R=I(:,:,1);
G=I(:,:,2);
B=I(:,:,3);
hue_one = mod((((G-B).*60)./(max(I,[],3)-min(I,[],3))),360);
hue_two = (((B - R).*60)./(max(I,[],3)-min(I,[],3))) + 120;
hue_three = (((R - G).*60)./(max(I,[],3)-min(I,[],3))) + 240;
if (R == G) & (R == B)
H = 0;
elseif (R >= G) & (R >= B)
H = hue_one;
elseif (G >= R) & (G >= B)
H = hue_two;
elseif (B >= R) & (B >= G)
H = hue_three;
end
V = max(I,[],3);
if V == 0
S = 0;
else
S = (max(I,[],3)-min(I,[],3))./max(I,[],3);
end
HSV(:,:,1) = H;
HSV(:,:,2) = S;
HSV(:,:,3) = V;
imshow(HSV)
values of S and V are loaded in the workspace without errors while the H returns an error.
Undefined function or variable 'H'.
Error in convertRGB (line 29)
HSV(:,:,1) = H;
i tried running my code line by line. after the if/elseif statements, there was no generated value of H. the variables hue_one, hue_two and hue_three also returned a matrix and can be found on the workspace pane. WHAT COULD HAVE BEEN THE PROBLEM OF THIS? THANK YOU.
0 个评论
回答(2 个)
Kan-Hua
2013-12-7
I would suggest you add a "else" statement in your first "if" block. It may be that your RGB components of the image you loaded does not match any of the if-condiations in your block, and thus your H is not assigned to any value.
For example:
if (R == G) & (R == B)
H = 0;
elseif (R >= G) & (R >= B)
H = hue_one;
elseif (G >= R) & (G >= B)
H = hue_two;
elseif (B >= R) & (B >= G)
H = hue_three;
else
H=0; %or whatever
end
Hope this helps. :)
0 个评论
Wayne King
2013-12-7
What do you expect these comparisons to yield:
if (R == G) & (R == B)
H = 0;
elseif (R >= G) & (R >= B)
H = hue_one;
elseif (G >= R) & (G >= B)
H = hue_two;
elseif (B >= R) & (B >= G)
H = hue_three;
end
If these are false for any element of these matrices (very, very likely), then H is not assigned anything.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!