-1
\$\begingroup\$

If we decode an image (any format) we will get matrix of pixels. For example consider a picture with resolution 10x10 and colour depth of 16777216. Therefore pixel is represented by 24 (888 RGB) bit 10x10 matrix data.

My doubt is how this data is stored in a Random Access Memory?

One option:

0x00 : first pixel(24 bit) 0x03 : second pixel (24 bit) ...

option two:

0x00 : red part of first pixel (8 bit) 0x01 : red part of second pixel (8 bit) ...

0x64 : green part of first pixel (8 bit) 0x65 : green part of second pixel (8 bit) ...

Which method is common? Or is there is any third method?

\$\endgroup\$
  • 7
    \$\begingroup\$ Those dimensions are purely a human concept. You just have a list of numbers. Store them how you like. \$\endgroup\$ – Majenko Jan 12 '15 at 11:06
  • 1
    \$\begingroup\$ Has this question any relation to your tags: fpga and vhdl? -- Memory is one dimensional from address 0 to N-1 (von-Neumann variables). You can directly map any n-dimensional matrix to n-1 or even 1-dimensional matrix if the dimensions are fixed. \$\endgroup\$ – Paebbels Jan 12 '15 at 11:53
  • \$\begingroup\$ Not quite in "any format". There are other color spaces besides RGB. \$\endgroup\$ – Fizz Jan 12 '15 at 11:58
  • \$\begingroup\$ Each pixel requires 3 bit, so you could store 2 pixels per byte or 10 pixels per 32-bit word (each solution requires some padding bits). \$\endgroup\$ – Paebbels Jan 12 '15 at 12:02
  • \$\begingroup\$ And please explain what you mean by your memory being 2D... because while that's usually the hardware organization of one DRAM chip, the fact that you can use multiple chips means that your address can be 3D too, in a sense. The chips/layers can be placed in actual 3D, for high densisty. Having said that, most memory controllers will linearize the address space to one dimension. I'm guessing you have something more specific in mind, something which isn't stated in your question. \$\endgroup\$ – Fizz Jan 12 '15 at 12:05
5
\$\begingroup\$

Your result isn't a matrix of MxNx3. Your result is a sequence of numbers. You can store them however you like.

Take the LCD screen you're reading this on, for instance. That is a 2D device, isn't it? Yet it looks like it would have a display of MxNx3. Look closer though. Very close. Get a magnifying glass and look reeeeeeal close.

It's actually a matrix of (Mx3)xN. Three physical pixels for every one you see - a red one, a green one, and a blue one.

enter image description here

So you actually have 3 times as many values in the X direction as you have pixels in the X direction.

That's a direct R/G/b interleaving, where every three entries in the matrix combine to make a single pixel value.

Or you could have three separate matrices of MxN - one to store the red pixel information, one the green and one the blue, if that makes more sense for what you're doing with the data.

Most systems though just choose to represent each pixel as a 24 or 32 bit value in a linear addressing scheme. Normally the 32 bits represent ARGB where A is an alpha value (transparency), and R, G and B represent the brightness of the three colours, all with 8 bit precision. 24 bit is the same but without the alpha information. (Unless you're Microsoft of course, when they like to do ABGR or other strange combinations in their file formats, but they're just daft).

Then that is just treated as a single list of numbers.

Say the image is 100x100 pixels in size, that would give you a list of 10,000 numbers to store in memory. The fact that it's a picture of 100x100 pixels is neither here nor there to the memory. It's only what you do with that data where the fact that it's a picture of 100x100 pixels matters.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thank you sir. Helpful. With respect to your answer I modified my question. Hopes it is more detailed now. \$\endgroup\$ – tollin jose Jan 13 '15 at 6:10
  • \$\begingroup\$ The most common is what I described (your option 1). But you don't want "most common". you want "most suitable". What works best for how you are then manipulating the data, \$\endgroup\$ – Majenko Jan 13 '15 at 10:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.