COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### differences between imagesc, image, and imshow and how do you extract RGB channels?

• Email
• Follow

Hi!
I'm just trying to work out what's the differences between the MATLAB built in functions of imshow, imagesc and image? From MATLAB's help, it says imagesc is the same as image just that the data is scaled to use the full colormap.
And imshow displays the grayscale image? But when I tried this, MATLAB didn't give me a grayscale image, instead it just gave me a full-colored image (i.e. the original colored image)

Also, how do I extract the RGB channels from a picture to turn it into a grayscale image? I know there's a function called rgb2gray to do this but our lecturer wants us to try to extract each channel from the image and find the mean of it, so its

newim= (im(:,:,1)+im(:,:,2)+im(:,:,3))/3

but when i run it, it says that there's a

Dimesion error of some sort: "index exceeds matrix dimension"
 0

See related articles to this posting

Do this
[rows columns numberOfColorPlanes] = size(im)
and tell me what it says.
Most likely im is monochrome so numberOfColorPlanes = 1, not to
mention the fact that you can't add up uint8's like that without
clipping at the high end (255).
 0

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <6c9498f4-255f-42af-b07b-54ac41e306ae@f20g2000yqi.googlegroups.com>...
> Do this
> [rows columns numberOfColorPlanes] = size(im)
> and tell me what it says.
> Most likely im is monochrome so numberOfColorPlanes = 1, not to
> mention the fact that you can't add up uint8's like that without
> clipping at the high end (255).

It says 133 106 and numberOfColorPlanes=2. That probably explains why it couldn't extract the parts of (:,:,2) and (:,:,3). So say, if the image did have a 3 color channels, this method would work to change the image to a grayscale image through this right?
And there's no further need to use a colormap(gray)?

So you mean, I can't directly do calculations on unit8? And I have to change it to double? Thanks!
 0

I think you got it backwards.  If it were monochrome you could use the
colormap() function (with gray or any of the other pseudocolor color
maps).  If it's RGB, then you cannot use colormap().  Once you convert
to grayscale, you have the *ability* to use the colormap (if you want
to), not "no further need" as you said.

Try this demo:
a = uint8(200);
% You expect 600, right?
b = (a + a + a)

result:
b = 255
It gets clipped to the max value for uint8.  You must convert to
floating point (single or double) to avoid clipping.
Are you also aware of the rgb2gray() and mat2gray() functions?
 0