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

  • 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

im=imread(filename)
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
Reply Charmaine 11/17/2010 6:46:04 AM

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
Reply ImageAnalyst 11/17/2010 11:14:46 AM


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
Reply Charmaine 11/17/2010 12:10:05 PM

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);
% Add up 3 a's.
% 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
Reply ImageAnalyst 11/17/2010 2:02:39 PM

3 Replies
818 Views

(page loaded in 0.038 seconds)

Similiar Articles:










7/24/2012 3:12:08 AM


Reply: