4

我已经开始学习图像处理,但我被困在这里,请帮助我。

灰度图像由 M x N 矩阵表示,其中矩阵的每个元素的值为 [0,255],表示强度。

例子:

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

这是 2 x 2 矩阵,是灰度图像。

现在我很困惑,无法获得如何表示每个像素值或强度是三个值的混合的 RGB 图像。

定义说,

RGB 图像用 M×N×3 数组表示,其中每个 3 向量对应于每个像素的红色、绿色和蓝色强度。

但是我无法理解上面的句子。请帮我理解意思。

先感谢您。

4

3 回答 3

3

灰度图像中,每个像素可以用一个数字表示,通常范围从 0 到 255。这个值决定了像素看起来有多暗(例如,0 是黑色,而 255 是亮白色)。

彩色图像中,每个像素可以由三个数字(每个数字的范围从 0 到 255)的向量表示,用于三个基色通道:红色、绿色和蓝色。这三个红色、绿色和蓝色 (RGB) 值一起用于决定该像素的颜色。例如,紫色可能表示为 128、0、128(中等强度的红色和蓝色混合,没有绿色)。

现在我将以你的例子来让你理解给定的定义。

假设一个 2 x 2 矩阵的彩色图像:

第1行:绿色,蓝色

第2行:红色,黑色

如果我用它的 RGB 值表示上面的颜色:

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

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

因此,M-by-N-by 3 描述了 M 是矩阵的行数,N 是矩阵的列数,3 是表示 RGB 值的向量的大小。是像素网格中的 RGB 表示。

于 2020-07-15T11:22:58.893 回答
1

Conceptually, a M-by-N RGB image is a 2D matrix where each matrix element is a vector with 3 values.

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. Each integer is formed by the red, green and blue values (each 8-bit integers) for example as so: red<<16 | green<<8 | blue (or equivalently red*256*256 + green*256 + blue).

  2. Using 3 separate MxN arrays, one for each color channel.

  3. Using a MxNx3 array, where the 3rd dimension is the "color dimension". 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.

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:

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). Thus, the array has M*N*3 elements, and three elements out of it together represent one pixel.

于 2018-08-23T15:48:50.873 回答
0

(A)RGB 像素通常保存为整数(32 位)。因此,每个通道由 8 位表示(为您提供 0 到 255 之间的范围)。数字的前 8 位(32-24)代表 alpha 通道,接下来的 8 位是红色通道(24-16),接下来的 8 位是绿色通道(16-8),最后 8 位是蓝色通道. 所以数组中的每个数字实际上代表了各个颜色通道的透明度 (alpha) 和 3 个强度值,因此也可以视为一个向量。M-by-N-by3描述了一个 MxN 矩阵,其中包含每个像素的向量(整数)以描述其颜色。

该定义进一步让您了解如何在三维空间中绘制/查看像素值。想象一个3D 图表,其中每个轴代表一个颜色通道。当您向图表添加特定颜色时,您会得到什么?描述颜色在源自原点的三维空间中的位置的向量!

于 2018-08-23T14:38:41.870 回答