将图像转换为原始位图文件

Conversion of an image to a raw bitmap file

我正在尝试 运行 具有以下要求的程序:

This program reads in an uncompressed gray-scale image with one byte per pixel and a size of 256*256 pixels (no image header)

如何转换 jpg 图像以满足上述要求。

在命令行使用 ImageMagick

magick input.jpg -resize 256x256\! -depth 8 -colorspace gray GRAY:image.raw

ImageMagick 包含在大多数 Linux 发行版中,并且可用于 macOS 和 Windows。在版本 6 及更早版本中,将上述命令中的 magick 更改为 convert

另一个免费工具是 IrfanView。它允许 select 需要的部分,对其进行裁剪,将大小更改为 256×X,再次裁剪为 256x256,更改为灰度并将其另存为 .raw。

如果您需要的不仅仅是转换(例如选择图像的重要部分等),IrfanView 非常方便。您还可以以相同的方式处理多张图片(select 每张图片上的相同区域,调整为 256x256 并将它们全部保存为 *.raw)。