简体   繁体   English

RGB图像的表示是什么?

[英]What is the representation of RGB image?

I have started studying image processing and I am stuck here, please help me.我已经开始学习图像处理,我被困在这里,请帮助我。

A gray scale image is represented by M by N matrix where the value of each element of the matrix is [0,255] which represents intensity.灰度图像由 M 和 N 矩阵表示,其中矩阵的每个元素的值为 [0,255],表示强度。

example:例子:

    row 1 : 2,120
    row 2 : 190, 40

This is 2 by 2 matrix which is a gray image.这是一个 2 x 2 的矩阵,它是一个灰度图像。

Now I am getting confused and not able to get how to represent a RGB image where each pixel value or intensity is a mix of three values.现在我很困惑,无法获得如何表示每个像素值或强度是三个值的混合的 RGB 图像。

The definition says that,定义说,

An RGB image is represented with an M-by-N-by3 array where each 3-vector corresponds to the red, green, and blue intensities of each pixel. RGB 图像用 M×N×3 阵列表示,其中每个 3 向量对应于每个像素的红色、绿色和蓝色强度。

But I am not able to understand the above sentence.但我无法理解上面的句子。 Please help me to get the meaning.请帮我理解意思。

Thank You in advance.先感谢您。

In grayscale images , each pixel can be represented by a single number, which typically ranges from 0 to 255. This value determines how dark the pixel appears (eg, 0 is black, while 255 is bright white).灰度图像中,每个像素都可以用单个数字表示,该数字的范围通常为 0 到 255。该值决定了像素显示的暗度(例如,0 是黑色,而 255 是亮白色)。

In colored images , each pixel can be represented by a vector of three numbers (each ranging from 0 to 255) for the three primary color channels: red, green, and blue.彩色图像中,每个像素可以由三个数字的向量表示(每个数字的范围为 0 到 255),用于三个主要颜色通道:红色、绿色和蓝色。 These three red, green, and blue (RGB) values are used together to decide the color of that pixel.这三个红色、绿色和蓝色 (RGB) 值一起使用来决定该像素的颜色。 For example, purple might be represented as 128, 0, 128 (a mix of moderately intense red and blue, with no green).例如,紫色可能表示为 128、0、128(中等强度的红色和蓝色的混合,没有绿色)。

Now I will take your example to give you the understanding of that given definition.现在我将以你的例子来让你理解给定的定义。

Let's say a colored image of 2 by 2 matrix:假设一个 2 x 2 矩阵的彩色图像:

row1: Green,Blue第 1 行:绿色、蓝色

row2: Red,Black row2:红色,黑色

If I represent this above colors with its RGB values:如果我用其 RGB 值表示上述颜色:

row1: [0,255,0],[0,0,255]第 1 行:[0,255,0],[0,0,255]

row2: [255,0,0],[0,0,0]第 2 行:[255,0,0],[0,0,0]

So, M-by-N-by 3 describes that M is number of rows of the matrix and N is the number of columns of the matrix, and 3 is the size of the vector which represents the RGB value.因此,M-by-N-by 3 描述了 M 是矩阵的行数,N 是矩阵的列数,3 是表示 RGB 值的向量的大小。 Here is the RGB representation in the pixel grid. 是像素网格中的 RGB 表示。

Conceptually, a M-by-N RGB image is a 2D matrix where each matrix element is a vector with 3 values.从概念上讲,M×N RGB 图像是一个 2D 矩阵,其中每个矩阵元素是一个具有 3 个值的向量。

There are many different ways you could represent this in physical memory.您可以通过多种不同的方式在物理内存中表示这一点。 For example:例如:

  1. Using a MxN array where each element is a 24-bit integer.使用 MxN 数组,其中每个元素都是 24 位整数。 Each integer is formed by the red, green and blue values (each 8-bit integers) for example as so: red<<16 | green<<8 | blue每个整数由红色、绿色和蓝色值(每个 8 位整数)组成,例如: red<<16 | green<<8 | blue red<<16 | green<<8 | blue red<<16 | green<<8 | blue (or equivalently red*256*256 + green*256 + blue ). red<<16 | green<<8 | blue (或等效的red*256*256 + green*256 + blue )。

  2. Using 3 separate MxN arrays, one for each color channel.使用 3 个独立的 MxN 阵列,每个颜色通道一个。

  3. Using a MxNx3 array, where the 3rd dimension is the "color dimension".使用 MxNx3 数组,其中第三个维度是“颜色维度”。 You would index this as img[i,j,k] , with k being 0, 1 or 2. Thus, one pixel is formed by 3 array elements.您可以将其索引为img[i,j,k]k为 0、1 或 2。因此,一个像素由 3 个数组元素组成。

This last format is the one described in the question.最后一种格式是问题中描述的格式。 Such a 3D array is typically implemented as a 1D array, with the indexing converted like this:这样的 3D 数组通常实现为 1D 数组,索引转换如下:

index = i + j * M + k * N*M;

or as this:或者像这样:

index = i * N*3 + j * 3 + k;

or in yet another different order, it does not matter (we're assuming 0-based indexing here).或者以另一种不同的顺序,这无关紧要(我们在这里假设是基于 0 的索引)。 Thus, the array has M*N*3 elements, and three elements out of it together represent one pixel.因此,该数组有M*N*3元素,其中的三个元素一起表示一个像素。

(A)RGB pixels are usually saved as intergers (32 bit). (A)RGB 像素通常保存为整数(32 位)。 Thereby, each channel is represented by 8 bit (giving you a range between 0 and 255).因此,每个通道由 8 位表示(为您提供 0 到 255 之间的范围)。 The first 8 bits(32-24) of the number represent the alpha channel, the next 8 bit the red channel (24-16), the next 8 bit the green channel (16-8) and the last 8 bit the blue channel.数字的前8位(32-24)代表alpha通道,接下来的8位代表红色通道(24-16),接下来的8位代表绿色通道(16-8),最后8位代表蓝色通道. So each number in the array actually represents the transparency (alpha) and the 3 intensity values of the respective color channels and thus can also be viewed as a vector.所以数组中的每个数字实际上代表了透明度 (alpha) 和各个颜色通道的 3 个强度值,因此也可以看作是一个向量。 M-by-N-by3 describes a MxN matrix containing the vector (the integer) for each pixel to describe its color. M-by-N-by3描述了一个 MxN 矩阵,该矩阵包含每个像素的向量(整数)以描述其颜色。

The defintion further gives you an idea how the pixel values can be plotted/viewed in the three dimensional space.该定义进一步让您了解如何在三维空间中绘制/查看像素值。 Imagine a 3D diagram where each axis represents one of the color channels.想象一个3D 图表,其中每个轴代表一个颜色通道。 What do you get when you add a specific color to the diagram?在图表中添加特定颜色时会得到什么? A vector which describes where the color is in the three dimensional space originating from the origin!描述颜色在源自原点的三维空间中的位置的向量!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM