Page 1 of 1

header-less binary image format

Posted: 2013-02-07T14:31:53-07:00
by NicolasRobidoux
What image format (or, more specifically, how should I create, without writing a custom C program) should I use if I want to store a one channel 16-bit image in binary, with no header, just the values strung one after another? Kind of binary 16-bit PGM with no header.
(Will dig more: Maybe the answer is out there already.)

Re: header-less binary image format

Posted: 2013-02-07T14:57:42-07:00
by snibgo

Code: Select all

convert x.png -depth 16 x.gray
Alternative suffixes are ".rgb" and ".rgba".

Re: header-less binary image format

Posted: 2013-02-08T05:52:00-07:00
by NicolasRobidoux
Thank you snibgo!
To convert it back to, say, png:

Code: Select all

convert -size WIDTHxHEIGHT -depth DEPTH input.gray output.png

Re: header-less binary image format

Posted: 2013-02-08T06:10:05-07:00
by snibgo
That's it. When I write a program that writes such a file, I find it convenient to have the option to spit out the "-size WIDTHxHEIGHT -depth DEPTH" as appropriate.

See also http://www.imagemagick.org/Usage/formats/#rgb . That reference doesn't say (but it's probably obvious) that the image starts at top-left, working across the image, then down. For 3 or 4 channels, the order within each pixel is RGB or RGBA.

Re: header-less binary image format

Posted: 2013-02-10T19:17:16-07:00
by anthony
The PGM image file format (Ascii or Binary forms) is simple enough for most C programs and includes the size and depth information. Look at the manpage "pgm" for format details.

Ascii forms for scripts, Binary for compactness and low level programming.

This way you keep the minimum meta data with the image data, in such a way that most image programs understand the format.


See also IM Examples, PbmPlus/NetPBM
http://www.imagemagick.org/Usage/formats/#pbmplus