Error message: Colormaps cannot have values outside range (0,1)
4 views (last 30 days)
Show older comments
Hello,
I'm trying to analyze the intensity of some images (RGB values) but when I run the code I get this error message:
Error using rgb2hsv>parseInputs (line 101)
Valid colormaps cannot have values outside the range [0,1].
Error in rgb2hsv (line 36)
[r, g, b, isColorMap, isEmptyInput, isThreeChannel] = parseInputs(varargin{:});
Error in AnalyzeIntensity071108 (line 64)
HSV(:,:,image_num)=rgb2hsv(RGB(:,:,image_num));
Has someone had a similar problem? If so, how did you fix it?
Thanks!
2 Comments
Adam
on 5 Jun 2019
Make sure your data doesn't have values outside that range. Without seeing any of your code or the image in question it's hard to say anything more. The error message is very clear as to what is wrong. As to why, we need more information to know. Maybe you are trying to pass an Unsigned8 image, although I imagine the error message would be different in that case, maybe you cast it to double without rescaling, maybe any one of a number of things.
Answers (1)
Walter Roberson
on 5 Jun 2019
Your image number is a scalar so RGB(:, :, image_num) is 2d not an rgb image. When you pass 2d to rgb2hsv then you need to pass a colormap of Nx3 values in the range 0 to 1
2 Comments
Walter Roberson
on 5 Jun 2019
RGB(:,:,image_num)=[Res1_r;Res1_g;Res1_b]';
does not create an RGB image. The right hand side is a 2D array that starts out putting color panes as additional rows, and then switches over to columns.
RGB(:,:,:,image_num) = cat(3, Res1_r, Res1_g, Res1_b);
HSV(:,:,:,image_num) = rgb2hsv(RGB(:,:,:,image_num));
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!