简体   繁体   中英

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.

example:

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

This is 2 by 2 matrix which is a gray image.

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.

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.

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).

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. These three red, green, and blue (RGB) values are used together to decide the color of that pixel. For example, purple might be represented as 128, 0, 128 (a mix of moderately intense red and blue, with no green).

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:

row1: Green,Blue

row2: Red,Black

If I represent this above colors with its RGB values:

row1: [0,255,0],[0,0,255]

row2: [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. Here is the RGB representation in the pixel grid.

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 red<<16 | green<<8 | blue 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.

(A)RGB pixels are usually saved as intergers (32 bit). Thereby, each channel is represented by 8 bit (giving you a range between 0 and 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. 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. M-by-N-by3 describes a MxN matrix containing the vector (the integer) for each pixel to describe its color.

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. 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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