imshow
imshow
Description
- imshow(I) displays image I in a Handle Graphics® figure, where I is a grayscale, RGB (truecolor), or binary image.
For binary images, imshow displays pixels with the value 0 (zero) as black and 1 as white.
imshow optimizes figure, axes, and image object properties for image display.
- imshow(I,[low high]) displays the grayscale image I, where [low high] is a two-element vector that specifies the display range for I.
The value low (and any value less than low) displays as black and the value high (and any value greater than high) displays as white.
imshow displays values in between as intermediate(中间的) shades of gray.
- imshow(I,[]) displays the grayscale image I, where [] is an empty matrix that specifies that you want imshow to scale the image based on the range of pixel values in I, using [min(I(:)) max(I(:))] as the display range.
- imshow(X,map) displays the indexed image X with the colormap map. A colormap matrix can have any number of rows, but it must have exactly 3 columns. Each row is interpreted as a color, with the first element specifying the intensity of red light, the second green, and the third blue. Color intensity can be specified on the interval 0.0 to 1.0.
- imshow(filename) displays the image stored in the graphics file specified by filename.
- imshow(___,Name,Value) displays an image, using name-value pairs to control aspects of the operation.
- himage = imshow(___) returns the handle to the image object created by imshow.
(本博客系原创,转载请注明出处:http://www.cnblogs.com/pfli1995/p/4658677.html)
(博主cnds中对应文章:http://blog.csdn.net/xuexiyanjiusheng/article/details/46956635)
注意:
- 为了节省存储空间,matlab为图像提供了特殊的数据类型uint8(8位无符号整数),以此方式存储的图像称作8位图像。
因此,matlab读入图像的数据是uint8,而matlab中数值一般采用double型(64位)存储和运算。所以要先将图像转为double格式的才能运算。
- 注意,imshow并不是只能显示灰度图像,如果unit8型或者double型数据是三维的,那么就会输出彩色图像。
- double型的取值为0~1之间,unit8取值0~255。如果是double类型,并且范围不是0~1,那么超过1的都被看作1,会显示为白色。
- 设 I 是一个uint8型的图像,如果直接 double(I) 再 imshow(double(I)) 的话,会输出错误的图像,有很多地方为白色,这个时候,需要先把转换为double后的图像的像素值先归一化到0~1区间,即 imshow(double(I)./255);第二种方法是,直接用 im2double ,会自动归一化到0~1,此时 imshow(im2double(I)) 即得到正确输出。 注意, im2double(I) 和 double(I)./255 是完全等价的,可以用它们分别作用后的矩阵相减,发现全为0。
- 如果想把数据从 double 型还回到 uint8 型,也有两种方法。 一是:im2uint8(I) ; 另一种是:uint8(round(I*255)) 。注意,博主也验证过了,这两种方法也是完全等效的。
- 另外还发现了一个函数:mat2gray, 它能够将范围在 0~255 的 uint8 或者 double 型的矩阵/图像数据转化为 0~1 的 double 型矩阵/图像数据。
索引图像的显示:
Display Indexed Image
Read a sample indexed image, corn.tif, into the workspace, and then display it.
[X,map] = imread('corn.tif'); imshow(X,map)