What are the formats used to represent values (color, contrast, brightness) in digital images? [closed]

4

What I want to do is: recognize pixel patterns in a file, or know how the assembler handles this (to make it easy to recognize these patterns).

Always wanted to create some application to manipulate images, doing object recognition, trying new chroma key techniques, etc. It is possible for example to know what a string of bytes written in ASCII means, but I do not know how the pixels are written.

And I've never encountered any material talking about how the bytes or pixels of a low-level image work. Knowing how you handle assembly can help.

My attempts were: to open the bitmap in a binary read program, where I did not find a pattern, and tried the basics also trying to open in an ASCII interpreter, where it was worse.

If I can figure out how to find these pixel patterns, I could use any language that manipulates files (even at a high level) to rewrite pixels. Or create some facial recognition algorithm, etc.

If anyone has any idea of what I should search, I thank you! To be fair, I found two great materials on the internet: An issue close to this in Yahoo Answers link A graphical library I've used for game programming link

But I need more than that!

I hope my doubt enriches the curiosity of many!

    
asked by anonymous 09.01.2017 / 13:08

1 answer

10

For images in memory, there are several possible formats, basically according to the number of bits per pixel, which can generally vary from 1 (black or white) to 32 (8 for red, 8 for green, 8 for blue and 8 for alpha ). The most common are:

  • 1 bit per pixel - Black or white.

  • 2 bits per pixel - Black, white and 2 shades of gray.

  • 4 bits per pixel - 16 shades of gray.

  • 8 bits per pixel - 256 shades of gray.

  • 2 bits per pixel - Black, white, cyan and magenta.

  • 2 bits per pixel - Black, white, green and red.

  • 4 bits per pixel - 16 basic colors chosen according to a color palette. Usually these colors are black, white and two shades of each of these colors: gray; blue; red; green; yellow; cyan and magenta.

  • 8 bits per pixel - 256 colors chosen arbitrarily from a palette / table.

  • 16 bits per pixel - Able to represent 65536 different colors. Of these bits, we have 5 for the red component, 6 for the green component and 5 for the blue component. The bit order can be RGB (red-green-blue) or BGR (blue-green-red).

  • 24 bits per pixel - capable of representing 16777216 different colors. 8 bits are used for each color component. The order of the bits can be RGB or BGR.

  • 32 bits per pixel - Same as 24 bits per pixel, but adding a byte to represent transparency, or more precisely the alpha , which is opacity, the opposite of transparency. An alpha of zero indicates total transparency, whereas an alpha of maximum value (255 in this case) indicates a totally opaque color. The transparency / opacity concept is useful when you want to draw images over one another. The order of the bits can be ARGB, RGBA, ABGR or BGRA.

File formats such as PNG, GIF, JPG, PCX, BMP, TGA, TIF, PGM, PPM, PPM etc. are often compressed and not all represent pixels directly. They have wide differences between them and each one has a unique format and quite different from the others. For example:

  • Some formats, such as BMP, PGM and PPM, represent pixels directly and sequentially.

  • PNG uses compression with some similarities to ZIP.

  • There are formats (for example, GIF) where there is a header with a palette / color table and each color is a number from 0 to 255 according to the table. In this case we can have 0 = blue, 1 = orange phosphorescent, 2 = moss green, 3 = golden ... Depending on how the table is.

  • Analog TV broadcasts use two components for color (chrominance) and one for brightness (luminance), to be compatible with black-and-white TV formats that only had brightness. This same concept is also used in JPG .

  • There are formats that use some very complicated math techniques that arise from the need to represent information that represents waves (often amplitude and phase) in the form of discrete and compact points. This comes from the fast Fourier transform and the discrete cosine transform . They are common in converting from analog to digital formats and also to squeeze as much information about the image into the smallest possible area as possible. JPG, for example, uses the discrete cosine transform .

So treating the pixels directly in many of these formats is difficult, and it's better for you to read the files, converting them into bitmaps directly into memory, and then manipulating those pixels directly into memory.

In practice, it's not worth worrying about file formats, it's worth it to use a library ready to read and write images in those formats and only worry about bitmaps in memory.

As colleague Luiz Vieira mentioned in comments, OpenCV is a rich and widely distributed library that already has many of these things ready to use.

    
09.01.2017 / 15:57