问题
I have a heightmap which is just a 16-bit wide big-endian array. I haven't looked into encoding a jpg or png from the raw data, but before I do I would like to know if there are any programs that I can download to view it as an image, because I want to know what it looks like.
When I do a search for viewing raw image data all the results return information about RAW image formats as used for camera image formats, which also differ between manufacturers, I don't think that's what I'm looking for. It's raw data as in a raw array, not the .RAW image format.
Thank you.
回答1:
Yes, with ImageMagick, which is installed on most Linux distros and is available for macOS and Windows.
So, if your image is 600x400 and just 16-bit grey values in a file called image.dat
, you would do this at the Terminal and get a file called output.jpg
which you can view:
convert -size 600x400 -depth 16 -endian MSB GRAY:image.dat -auto-level output.jpg
If there is a 512 byte header, you would use:
convert -size 600x400+512 ...
If the data are colour rather than greyscale, use:
convert -size 600x400 -depth 16 -endian MSB RGB:image.dat ...
If you want a PNG instead of a JPG, use:
convert ... result.png
As an alternative, you could consider writing a PGM (Portable Grey Map) or
PPM (Portable Pix Map) format file from your program which is extremely easy, see NetPBM Wiki description and would have your image size in it - so it would be self-contained. One would normally use P5
(for greyscale) or P6
(for colour) with binary, rather than ASCII, data. Then you can convert that simply to a JPEG (or PNG) afterwards with ImageMagick and never have to worry about writing JPEGs or PNGs or linking with libraries:
convert result.pgm result.png # convert greyscale results to PNG
convert result.ppm result.jpg # convert colour results to JPG, or PNG, or TIFF, or GIF...
来源:https://stackoverflow.com/questions/41698807/is-there-a-program-to-view-a-raw-array-as-an-image