Imagemagick convert png 16 bit to raw

I am trying to convert a 16 bit gray PNG to a raw file. Image size - 640 * 480.

First determine:

$ identify image.png 
image.png PNG 640x480 640x480+0+0 16-bit PseudoClass 65536c 299KB 0.000u 0:00.000

I expect the result file to have a size of 640 * 480 * 2 bytes.

Attempt 1:

$ convert image.png -depth 16 image.raw

This gives a file size of 330,805 bytes. Its first 16 bytes look like this:

0x00000000: 89504E47 0D0A1A0A 0000000D 49484452     .PNG........IHDR

Attempt 2:

$ convert image.png -depth 16 image.rgb

This gives a file size of 1843200 bytes, which is 640 * 480 * 2 * 3.

I am running imagemagick version 6.7.7-10 on Ubuntu 14.04.

Any ideas?

+5
source share
2 answers

Updated Answer

, , , , , stream ImageMagick .

,

stream -map r -storage-type short image.png image.raw

(-map r), , , 16- (-storage-type short) image.raw.

, - .

RGB , 3 - R, G B. PGM (Portable Greymap), ...

convert image.png -depth 16 pgm:-
P5
640 480
65535
<binary data> < binary data>

PGM , , P , , , MAX VALUE . MAX VALUE 65535, 255, 16-.

:

convert image.png -depth 16 pgm:- | tail -c 614400 > file.raw

614400, bash, ImageMagick ( * * 2 /) :

bytes=$(identify -format "%[fx:h*w*2]" image.png)
convert image.png -depth 16 pgm:- | tail -c $bytes > file.raw
+9

All Articles