Error using rgb2gray scale conversion. Using the function in a known RGB preinstalled image in matlab gives a "MAP must be a m x 3 array" error
1 view (last 30 days)
Show older comments
Mariam
on 25 May 2017
Answered: Walter Roberson
on 25 May 2017
I am doing image segmentation of round objects that have similar color to their background. The image is RGB but the RGB values give tones of gray, notice even though the image looks gray it is not in grayscale. In the segmentation process I have to apply gradient filters and opening and closing by reconstruction in order to separate the round objects from the background before making the binary mask that I will use for segmentation. Some of the functions I used in this process accept 2D arrays inputs only. In fact, binarization of the image itself can only be done in 2D array inputs, not in RGB images which are a 3D array. So, I am trying to convert my RGB image which looks gray but is not in grayscale before doing anything else. But, I get the following error form MATLAB when I use the rgb2gray function: Error using rgb2gray>parse_inputs (line 77) MAP must be a m x 3 array.
Error in rgb2gray (line 52) [X, threeD] = parse_inputs(X);
Error in Mask_Biophysics (line 2) Frame= rgb2gray(rgb);
Does anyone know what this error means and how to fix it ? This is the part of the code that is giving me the error:
rgb= imread('kids.tif'); Frame= rgb2gray(rgb);
Notice I am using a pre installed matlab image "kids.tif", So, the error has nothing to do with my particular image. kids.tif is an RGB color image in matlab
0 Comments
Accepted Answer
Walter Roberson
on 25 May 2017
kids.tif is not an RGB image, it is a pseudocolor image
[idx, cmap] = iread('kids.tif');
Frame = rgb2gray( ind2rgb(idx, cmap));
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!