Portable pixmap is a set of portable image formats defined by the netpbm project. These images are in the same format.
It is easier to process and has nothing to do with the platform. Therefore, portable is a relatively direct image format. For example, PPM stores the RGB values of each vertex separately.
. Therefore, files in the PPM format are not compressed and relatively large. However, because the image format is simple, they are generally used as intermediate files for image processing (files will not be lost ).
Information), or saved as a simple image format.
Format Analysis
Several netpbm image formats are differentiated by their color types,PBM is a monochrome graph., Only black and white,PGM is a grayscale image.,Ppm is representative
CompleteRGB Images, Sometimes collectively referred toPNMFormat.
(1) File Header
The file header consists of three parts: these parts are separated by carriage return or line feed (but the requirements in the PPM standard are spaces)
The first part is the magic number file.
Each netpbm image consists of two bytes of magic number (ASCII) to identifyType(PBM/PGM/ppm) andEncoding(ASCII or binary)
P1 monochrome image asⅱ PBM
P2 grayscale image asⅱ PGM
P3 pixel map asⅱ ppm
P4 monochrome diagram binary PBM
P5 grayscale binary PGM
P6 pixel image binary PPM
The second part isImage width and height(Separated by spaces), expressed in ASCII.
The third part is the description.Maximum pixel colorCan describe the color value of more than one byte (0-255.
In addition, you can use "#" to insert comments in the above three sections. The comments are from the end of the line (Press ENTER or line feed.
(2) Image Data Section
The ASCII format is arranged in the order of RGB and stored in ASCII format. In addition, the RGB format is separated by spaces. Each line of the image is separated by carriage return.
For binary format, the RGB values of each pixel are stored sequentially and written to files in binary format without any separation.
Ppm
Example 1:
P6 1024 778 255
Example 2:
P6
1024 778
255
Example 3:
P6 # ppm File Format
1024/778 # width and height
255
Normally, images are stored from top to bottom and left to right. Color components are stored in the red-green-blue sequence.
PGM
The format file stores grayscale images, that is, each pixel uses a value instead of three (R, G, B ). The only difference with ppm is that P2 and
P5, which represents data with ASCII and bytecode.
For example:
P2
24 7
15
PBM
The ASCII 0 or 1 is used to represent data, 0 is white, and 1 is black. Different from ppm and PGM, the header is missing the third line, because the maximum color of the third line
The value is meaningless in this mode.
As follows:
P1
# PBM example
24 7
[Image Format] ppm/PGM/PBM encoding details