imagemagick convert png 16 bit to raw

gray might be the format you want:

convert image.png -depth 16 image.gray

This command stores each pixel in 2 bytes and nothing else in the file.

Here I provide a minimal synthetic example: https://superuser.com/questions/294270/how-to-view-raw-binary-data-as-an-image-with-given-width-and-height/978432#978432

enter image description here

.raw is not really a "pixel only" format: it does contain some metadata: https://en.wikipedia.org/wiki/Raw_image_format#File_contents


Updated Answer

It occurred to me since answering you, that there is a simpler method of doing what you want, that takes advantage of ImageMagick's little-used stream tool, to stream raw pixel data around.

In effect, you can use this command

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

which will read the Red channel (-map r), which is the same as the Green and Blue channels if your image is greyscale, and write it out as unsigned 16-bit shorts (-storage-type short) to the output file image.raw.

This is cleaner than my original answer - though should give identical results.

Original Answer

If you write an RGB raw file, you will get 3 channels - R, G and B. Try writing a PGM (Portable Greymap) like this...

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

The PGM format is detailed here, but suffice to say that there is header with a P followed by a digit describing the actual subtype, then a width and height and then a MAX VALUE that describes the range of the pixel intensities. In your case, the MAX VALUE is 65535 rather than 255 because your data are 16-bit.

You can the strip the header like this:

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

If you are converting lots of files of different sizes and dislike the hard-coded 614400, and are using bash, you can get ImageMagick to tell you the size (height * width * 2 bytes/pixel) and use that like this:

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