views:

233

answers:

1
>> I = imread('D:\Works\matlab\SecCode.php.png','png');
>> imshow(I);

The above code always shows an all-black image. What's wrong with it?

The image I'm using is this one:

alt text

+2  A: 

Ahhh, I see now. The problem is you have an indexed image and need to get the colormap argument from IMREAD as well. Try this:

[I,map] = imread('D:\Works\matlab\SecCode.php.png','png');
imshow(I,map);

A description of the different types of images in MATLAB can be found here. Here's a brief summary:

  • Binary images: The image is a logical array where each pixel has the value 0 or 1.
  • Indexed images: The pixels in the image store indices into a colormap, which is an M-by-3 array of RGB values. The colormap is often stored with the indexed image in the image file.
  • Grayscale images: The pixels in the image each contain a single value representing the intensity.
  • Truecolor images: The image is an M-by-N-by-3 array where each pixel has a red, green, and blue color component.
gnovice
Is this what you mean by **indexed** :http://en.wikipedia.org/wiki/Indexed_color ?
@user198729: Yes, that is what I meant. I also added some MATLAB documentation links above for you.
gnovice
Thanks,can you also elaborate a little about this image,which is found in your link:http://www.mathworks.com/access/helpdesk/help/toolbox/images/introa.gif
@user198729: That image illustrates a Truecolor image. They are 3-D data arrays (M-by-N-by-3). In that picture, a section of the image is displayed as a set of 3 M-by-N arrays, one for red values, one for green values, and one for blue values. The values range from 0 to 1 for each pixel, with higher values indicating a larger component of that color for that pixel.
gnovice
Yes,but which 3 of them denotes the RGB for the **same** point in the image?
@user198729: Note that there is one value shown in **bold** in the each of the red, green, and blue panels. These values create a reddish brown color (probably one of the pixels for one of the dark red peppers). Even though there's a circle around the yellow pepper in the image, the data in the inset is probably for a different area and is just there to illustrate what the matrix contents typically look like.
gnovice

related questions