Size of one pixel in Image

As it was descriped in our project: Images are represented as arrays of 8-bit integers. Three consecutive integers represent the respective colors of a pixel.

Images are represented as arrays of 8-bit integers: is it just because every single color need 8 bits?
Three consecutive integers represent the respective colors of a pixel: so one pixel takes 24 bits, which is different like the classic way 32 bits…without an extra 8 bits for the A element in ARGB?

So do we need to use size_t to use the single elements in the array?

Hi,

Yes, the maximum value for one channel is 255, so you need exactly 8 bits (which can represent the numbers from 0 to 255) to ensure that every value can be reached.

size_t is just an unsigned integer type. I’m not sure, what you mean with

You can access elements of an array by dereferencing the pointer. For example:

Let array be the pointer to the first element of an integer array with 5 elements. If you now want to access the 3rd elemnt, you need to code something like this:

int third_element = array[2]; //this is just syntactic sugar for *(array+2)

We need to write array[2], because the indices start with 0.
So, you need some integer to add if you want to access the content of your array, but you could also use type int and don’t need to use something of type size_t for that.

Hope this answered your question.
Lisa :smiley:

2 Likes

Hello Lisa, thanks for your detailed explanation and it helped me a lot :grin: