MATLAB rgb

这篇博客介绍了MATLAB中RGB图像的存储和处理方式。RGB图像由红、绿、蓝三色分量组成,每个像素的色彩由对应分量的强度决定。在MATLAB中,RGB图像可以是double、uint8或uint16类数组。对于double类型的RGB数组,颜色分量值范围在0到1之间。图像函数`image`用于显示RGB图像,而`colormap`用于设置颜色映射。此外,博客还讨论了如何在double型和uint8型之间转换图像数据,以及`imread`函数如何处理灰度和RGB图像。


RGB (Truecolor) ImagesAn RGB image, sometimes referred to as a "truecolor" image, is stored in MATLAB 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 double, uint8, 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. For example,

image(RGB)
The next figure shows an RGB image of class double.

To determine the color of the pixel at (2,3), you would 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

MATLAB中,数值一般都采用double型(64位)存储和运算,为了节省存储空间,MATLAB为图像提供了特殊的数据类型uint88位无符号整数),以此方式存储的图像称为8位型像。函数image能够直接显示8位图像,但8位型数据和double型数据在image中意义不一样,对于索引图像,数据矩阵中的值指定该像素的颜色种类在色图矩阵中的行数。当数据矩阵中的值为0时,表示用色图矩阵中第一行表示的颜色绘制;当数据矩阵中的值为1时,表示用色图矩阵中的第二行表示的颜色绘制该像素,数据与色图矩阵中的行数总是相差1。所以,索引图像double型和uint8型在显示方法上没有什么不同,只是8位数据矩阵的值和颜色种类之间有一个偏差1。调用格式均为image(x); colormap(map);对于灰度图像,uint8表示范围[0255]double型表示范围[01]。可见,double型和uint8型灰度图像不一样,二者转换格式为:

I8=uint8 (round (I64*255));

I64=double (I8)/255;

反之,imread根据文件中的图像种类作不同的处理。当文件中的图像为灰度图像时,imread把图像存入一个8位矩阵中,把色图矩阵转换为双精度矩阵,矩阵中每个元素值在[01]内;当为RGB图像时,imread把数据存入到一个8RGB矩阵中。 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值