regarding the conversion of rgb to gray scale

what does the code if(size(imagen,3)==3) mean ,why should we % it with RGBimage sir?

Answers (2)

It's checking if the image variable "imagen" is indeed a 3D true color image. It makes for robust code to double check for things like that. Maybe it's not an rgb image, despite what you thought. Maybe it's really a grayscale, indexed, or multispectral (more than 3 color channels) image. It's always a good idea to double check in case it might make a difference, like if you need to pass the image into rgb2gray(), conv2(), or other functions that require the image to be a certain type of image.
If you have an array A with dimension mxnx3
size(A,1)=m
size(A,2)=n
size(A,3)=3
To use rgb2gray your array should be mxnx3.

Categories

Asked:

XYZ
on 17 Jul 2013

Community Treasure Hunt

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

Start Hunting!