PPM Crossplatform Images: Maxbox Starter The Portable Pixmap Format
PPM Crossplatform Images: Maxbox Starter The Portable Pixmap Format
1 https://en.wikipedia.org/wiki/Netpbm#File_formats
1/7
So beside the plain format also a raw (binary) format exists. The
ASCII ("plain") formats (P1-P3) allow for human readability and
easy transfer to other platforms; the binary ("raw") formats (P4-
P6) are more efficient in file size but may have native byte-order
issues. This is how we define the header first:
Let's start with the code. Each file opens with a two-byte magic
number (in ASCII) that identifies the type of file, the magic
number is either an ASCII character string ”P1”, ”P2”,”P3”,”P4”,
”P5” or “P6” depending upon the storage method used. “P1” and “P4”
indicate that the image data is in a bitmap as black and white.
We use a pattern helper class as a procedure() to save the bitmap
as a PPM file:
procedure TBitmapHelperSaveAsPPM_4(FileName: TFileName; bmp: TBitmap;
useGrayScale: Boolean);
var
i,j: Integer;
Header: AnsiString;
ppm: TMemoryStream;
agb: TBytes;
2/7
We use a memory-stream and a byte-array for storage. Using a byte
array can lead to some optimizations that can make accessing and
changing information in the array faster than it would be with
arrays of other types, in our case we define a 3 bytes array:
begin
ppm:= TMemoryStream.Create;
try
Header:= Format('P6'#10'%d %d'#10'255'#10,[bmp.Width, bmp.Height]);
writeln(Header);
ppm.WriteBuffer((Header), Length(Header));
setlength(agb,3)
for i:= 0 to bmp.Width- 1 do
for j:= 0 to bmp.Height- 1 do begin
if useGrayScale then
agb:= InttoBytes(ColorToGray(ColorToRGB(bmp.Canvas.Pixels[j,i])))
else
agb:= InttoBytes(ColorToRGB(bmp.Canvas.Pixels[j,i]));
ppm.Write(stringOf(agb), 3);
//ppm.Write(BytetoString(rgb),3);
end;
ppm.SaveToFile(FileName);
finally
ppm.Free;
end;
end;
A PPM file consists of two parts, a header and the image data
stored within WriteBuffer(). The header consists of at least three
parts normally delineated by carriage returns and/or linefeeds but
the PPM specification only requires white space.
3/7
Interesting is a grayscale function as bool decision useGrayScale:
4/7
The last part of the header gives the maximum value of the colour
components for the pixels, this allows the format to describe more
than some single byte(0..255) colour values.
model_path = “./models/yolo-tiny.h5”
input_path = “./input/manmachine.ppm”
output_path = “./output/manmachineout.png”
5/7
Illustr. 5: Object Detection from PPM
Intermediate
To detect only some of the objects above, I will need to call the
CustomObjects method and set the name of the object(s) we want to
detect to. Netpbm contains over 220 separate programs in the
package, most of which have "pbm", "pgm", "ppm", "pam", or "pnm"
in their names. The programs are designed to be minimal building
blocks that can be used in various combinations to do other things
like image detection on an Arduino with TensorFlowLite.
6/7
Conclusion:
The portable pixmap format(PPM), the portable graymap format(PGM)
and portable bitmap format(PBM) are image file formats designed to
be easily exchanged between platforms. They are also sometimes
referred collectively as the portable anymap format(PNM). These
formats are a convenient (simple) method of saving image data.
And the format is not even limited to graphics, its definition
allowing it to be used for arbitrary three-dimensional matrices or
cubes of unsigned integers.
http://www.softwareschule.ch/examples/sphere2.txt
http://www.softwareschule.ch/examples/sphere2.htm
http://www.softwareschule.ch/examples/detector2.htm
Ref:
https://people.cs.clemson.edu/~dhouse/courses/405/notes/ppm-files.pdf
http://paulbourke.net/dataformats/ppm/
Blog:
https://maxbox4.wordpress.com
https://softwareschule.code.blog/2020/11/18/sphere-script/
7/7