header-less binary image format

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

header-less binary image format

Post 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.)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: header-less binary image format

Post by snibgo »

Code: Select all

convert x.png -depth 16 x.gray
Alternative suffixes are ".rgb" and ".rgba".
snibgo's IM pages: im.snibgo.com
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: header-less binary image format

Post by NicolasRobidoux »

Thank you snibgo!
To convert it back to, say, png:

Code: Select all

convert -size WIDTHxHEIGHT -depth DEPTH input.gray output.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: header-less binary image format

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: header-less binary image format

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply