0
votes

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

1
You don't show how you call rgb2gray or the type/range of your input image. Apparently MATLAB thinks your image is a colormap. - beaker
Frame1= imread('kids.tif'); Frame= rgb2gray(Frame1); - user27407
What I posted above is my actual code. What you mentioned is what I interpreted from the error. So, I tried the same code with one of the pre installed matlab images "kids.tif - user27407
Please put updates in the question itself using edit. - beaker
I just edited the question. Thanks for the tips on using stackoverflow. I hope you can help me fix the error - user27407

1 Answers

0
votes

tif files (at least 'kids.tif') are 2D index matrices with colormap and not 3D (RGB) matrices. rgb2gray accepts 3D RGB matrices or 2D index matrix with its matching colormap. try:

[rgb,cmap]= imread('kids.tif');
Frame= rgb2gray(rgb,cmap);