转载自https://www.mathworks.com/help/matlab/creating_plots/image-types.html

Image Types

Indexed Images

An indexed image consists of a data matrix, X, and a colormap matrix, mapmap is an m-by-3 array of class double containing floating-point values in the range [0, 1]. Each row of map specifies the red, green, and blue components of a single color. An indexed image uses “direct mapping” of pixel values to colormap values. The color of each image pixel is determined by using the corresponding value of X as an index into map. Values of X therefore must be integers. The value 1 points to the first row in map, the value 2 points to the second row, and so on. Display an indexed image with the statements

image(X); colormap(map)

A colormap is often stored with an indexed image and is automatically loaded with the image when you use the imread function. However, you are not limited to using the default colormap—use any colormap that you choose. The description for the property CDataMapping describes how to alter the type of mapping used.

The next figure illustrates the structure of an indexed image. The pixels in the image are represented by integers, which are pointers (indices) to color values stored in the colormap.

The relationship between the values in the image matrix and the colormap depends on the class of the image matrix. If the image matrix is of class double, the value 1 points to the first row in the colormap, the value 2 points to the second row, and so on. If the image matrix is of class uint8 or uint16, there is an offset—the value 0 points to the first row in the colormap, the value 1 points to the second row, and so on. The offset is also used in graphics file formats to maximize the number of colors that can be supported. In the preceding image, the image matrix is of class double. Because there is no offset, the value 5 points to the fifth row of the colormap.

Grayscale (Intensity) Images

A grayscale image, sometimes referred to as an intensity image, is a data matrix I whose values represent intensities within some range. A grayscale image is represented as a single matrix, with each element of the matrix corresponding to one image pixel. The matrix can be of class doubleuint8, or uint16. While grayscale images are rarely saved with a colormap, a colormap is still used to display them. In essence, grayscale images are treated as indexed images.

This figure depicts a grayscale image of class double.

To display a grayscale image, use the imagesc (“image scale”) function, which enables you to set the range of intensity values. imagesc scales the image data to use the full colormap. Use the two-input form of imagesc to display a grayscale image, for example:

imagesc(I,[0 1]); colormap(gray);

The second input argument to imagesc specifies the desired intensity range. The imagesc function displays I by mapping the first value in the range (usually 0) to the first colormap entry, and the second value (usually 1) to the last colormap entry. Values in between are linearly distributed throughout the remaining colormap colors.

Although it is conventional to display grayscale images using a grayscale colormap, it is possible to use other colormaps. For example, the following statements display the grayscale image I in shades of blue and green:

imagesc(I,[0 1]); colormap(winter);

To display a matrix A with an arbitrary range of values as a grayscale image, use the single-argument form of imagesc. With one input argument, imagesc maps the minimum value of the data matrix to the first colormap entry, and maps the maximum value to the last colormap entry. For example, these two lines are equivalent:

imagesc(A); colormap(gray)
imagesc(A,[min(A(:)) max(A(:))]); colormap(gray)

RGB (Truecolor) Images

An RGB image, sometimes referred to as a truecolor image, is stored as an m-by-n-by-3 data array that defines red, green, and blue color components for each individual pixel. RGB images do not use a palette. The color of each pixel is determined by the combination of the red, green, and blue intensities stored in each color plane at the pixel's location. Graphics file formats store RGB images as 24-bit images, where the red, green, and blue components are 8 bits each. This yields a potential of 16 million colors. The precision with which a real-life image can be replicated has led to the nickname “truecolor image.”

An RGB MATLAB array can be of class doubleuint8, or uint16. In an RGB array of class double, each color component is a value between 0 and 1. A pixel whose color components are (0,0,0) is displayed as black, and a pixel whose color components are (1,1,1) is displayed as white. The three color components for each pixel are stored along the third dimension of the data array. For example, the red, green, and blue color components of the pixel (10,5) are stored in RGB(10,5,1)RGB(10,5,2), and RGB(10,5,3), respectively.

To display the truecolor image RGB, use the image function:

image(RGB)

The next figure shows an RGB image of class double.

To determine the color of the pixel at (2,3), look at the RGB triplet stored in (2,3,1:3). Suppose (2,3,1) contains the value 0.5176, (2,3,2) contains 0.1608, and (2,3,3) contains 0.0627. The color for the pixel at (2,3) is

0.5176 0.1608 0.0627

最新文章

  1. Repository 仓储,你的归宿究竟在哪?(二)-这样的应用层代码,你能接受吗?
  2. Manage application.conf in several environments
  3. eclipse中配置maven
  4. javascript运算符——条件、逗号、赋值、()和void运算符
  5. tomcat中server.xml配置详解
  6. win 7 IIS 配置
  7. 介绍 Android 的 Camera 框架
  8. fastjson 的简单说明及使用
  9. 序列化和持久化 merge方法和saveOrUpdate方法
  10. ZigBee研究之旅(二)
  11. MySQL 存储过程 经常使用语法
  12. 继承control的自定义TextBox
  13. 0.0 ABP官方文档翻译目录
  14. dd的用法
  15. GetConsoleScreenBufferInfo 函数--获取控制台屏幕缓冲区信息
  16. Eclipse rap 富客户端开发总结(4):如何搭建 rap 中文开发环境
  17. Apache Spark 2.2.0 中文文档 - Spark RDD(Resilient Distributed Datasets)论文 | ApacheCN
  18. [Linux] Configure iSCSI on Linux5 (both target and initiator)
  19. R语言--输入输出
  20. ImageView和onTouchListener实现,点击查看图片细节

热门文章

  1. Linux练习题--打印文本第10行
  2. 记一次使用tika解析文件文本导致的内存溢出问题
  3. TrueNAS安装 一个厉害的nas系统
  4. Ubuntu18.04修改IP地址的方法
  5. LeetCode-1610 可见点的最大数目
  6. windows-sam文件
  7. springmvc关于通过使用路径占位符出现中文乱码解决办法
  8. C# DevExpress GridControl下动态创建列的方法
  9. react 02 组件state click
  10. 使用Java API操作Neo4j