image-processinglarge-datalarge-filesrawimage

Converting raw images without headers


I have very large (20000x20000+) raw image files where each pixel is represented by 3 bytes. I know the resolution of each image. Example (for a 4x4 image):

+----------------+----------------+----------------+----------------+
|                |                |                |                |
|  R    G    B   |  R    G    B   |  R    G    B   |  R    G    B   |
| 0x00 0x01 0x02 | 0x03 0x04 0x05 | 0x06 0x07 0x08 | 0x09 0x0A 0x0B |
|                |                |                |                |
+----------------+----------------+----------------+----------------+
|                |                |                |                |
|  R    G    B   |  R    G    B   |  R    G    B   |  R    G    B   |
| 0x0C 0x0D 0x0E | 0x0F 0x10 0x11 | 0x12 0x13 0x14 | 0x15 0x16 0x17 |
|                |                |                |                |
+----------------+----------------+----------------+----------------+
|                |                |                |                |
|  R    G    B   |  R    G    B   |  R    G    B   |  R    G    B   |
| 0x18 0x19 0x1A | 0x1B 0x1C 0x1D | 0x1E 0x1F 0x20 | 0x21 0x22 0x23 |
|                |                |                |                |
+----------------+----------------+----------------+----------------+
|                |                |                |                |
|  R    G    B   |  R    G    B   |  R    G    B   |  R    G    B   |
| 0x24 0x25 0x26 | 0x27 0x28 0x29 | 0x2A 0x2B 0x2C | 0x2D 0x2E 0x2F |
|                |                |                |                |
+----------------+----------------+----------------+----------------+

How do I convert them to BMP images?


Solution

  • Easy. Use ImageMagick in Terminal (or "Command Prompt" thing on Windows). If your file is 1920 px wide by 1080 px tall:

    magick -size 1920x1080 -depth 8 RGB:YOURFILE output.bmp
    

    Not sure why anyone would willingly choose to use BMP format though. I would prefer PNG:

    magick -size 1920x1080 -depth 8 RGB:YOURFILE output.png
    

    Use convert in place of magick if using v6 ImageMagick.


    Or, even easier (since it requires no software installation), make a header and convert them to NetPBM files which Photoshop, GIMP, feh can all read:

    { printf "P6\n%d %d\n255\n" WIDTH HEIGHT ; cat YOURFILE; } > result.ppm