简体   繁体   English

使用C ++从16位数据创建灰度图像

[英]Create a grayscale image from 16-bit data using C++

I have an array of 16-bit values and I want to create an image (such as BMP) so that I can view it. 我有一个16位值的数组,我想创建一个图像(例如BMP)以便可以查看它。 Does anyone have suggestions of how to do this? 有没有人建议如何做? Thanks 谢谢

Say your image is 200px by 100px. 假设您的图片是200px x 100px。 Write the 20,000 16-bit vales to a binary file. 将20,000个16位值写入二进制文件。

At the commandline, run ImageMagick : 在命令行中,运行ImageMagick

magick -depth 16 -size 200x100 gray:yourFile.bin image.png

Or, if you want a JPG 或者,如果您想要JPG

magick ... image.jpg

For a tiny bit more effort, you could write a 16-bit PGM file which would have the benefit that it contains its dimensions and bit depth in a small ASCII header so the conversion in ImageMagick is simpler, and other programs such as GIMP can read it: 只需花费一点点的精力,您就可以编写一个16位的PGM文件,该文件的好处是它在一个小的ASCII标头中包含其尺寸和位深度,因此ImageMagick中的转换更加简单,并且其他程序(例如GIMP)可以读取它:

magick yourFile.pgm  image.jpg

The header would be: 标头为:

P5
200 100
65535
... binary data as above ...

See Wikipedia NetPBM article . 请参阅Wikipedia NetPBM文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM