Output error vector in the grayscale

I have this piece of code:
resRGB = HSVtoRGB(resHSV);
but I have this error:
Input error: please pass as input a vector variable with 3 elements with value in the range [0,1]
How do I have to improve my code?

2 Comments

I'm guessing that resHSV is not in fact "a vector variable with 3 elements with value in the range [0,1]" (or is it?), so what is resHSV?
Also, you may consider using the built-in MATLAB function hsv2rgb to convert HSV colors to RGB.
HSVtoRGB is like to hsv2rgb and it works.
Then I have:
resH = 2 * atan2(A, B);
resS = 2 * atan2(C, D);
resV = 2 * atan2(E, F);
resHSV is resH; resS; resV. A vector with 3 elements.
If I write:
resRGB = HSVtoRGB
it works, but thi isn't the results I expect.

Sign in to comment.

 Accepted Answer

Why not use the built-in hsv2rgb()
resRGB = hsv2rgb(resHSV);

5 Comments

Eva Comeni
Eva Comeni on 27 Feb 2022
Edited: Eva Comeni on 27 Feb 2022
Because my professor wants I create this function (hsv2rgb)
If I use hsv2rgb, I havre this error:
Valid colormaps cannot have values outside the range [0,1].
It works. No colormap is used. You must have done something wrong.
rgbImage = imread('peppers.png');
% Convert rgb into hsv:
hsvImage = rgb2hsv(rgbImage);
% Return to rgb by converting hsv to rgb
rgbImage = hsv2rgb(hsvImage);
But if your professor requires you to write your own code (and not turn in our code as your own), then you'd better do that.
Write:
resRGB = HSVtoRGB(resHSV);
is it the same to
HSVtoRGB = resHSV;
resRGB = HSVtoRGB;
?
No those would do diffferent things and make diffferent assumptions.
resRGB = HSVtoRGB(resHSV);
assumes that HSVtoRGB is a function, and that resHSV is a 3-D array.
While
HSVtoRGB = resHSV;
would take the resHSV array and make a copy of the array in a new array called HSVtoRGB. HSV2RGB should not be an existing function. Then if you do
resRGB = HSVtoRGB;
you're essentially overwriting the original resRGB array with HSVtoRGB array, which is the same thing as overwriting resRGB array with the resHSV array, which is crazy since that array is from a different color space.
Ok, thank you. So, how I could improve this:
resRGB = HSVtoRGB(resHSV);
?
N.B. HSVtoRGB (this works fine) is like hsv2rgb.

Sign in to comment.

More Answers (1)

yes,sir,may be check resHSV value,such as
resHSV = [.6 1 1; .6 .7 1; .6 .5 1; .6 .3 1; .6 0 1]
resHSV = 5×3
0.6000 1.0000 1.0000 0.6000 0.7000 1.0000 0.6000 0.5000 1.0000 0.6000 0.3000 1.0000 0.6000 0 1.0000
size(resHSV)
ans = 1×2
5 3
rgb = hsv2rgb(hsv);
surf(peaks);
colormap(rgb);
colorbar

Categories

Community Treasure Hunt

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

Start Hunting!