Problem: I have printed some binary data from gdb which I'd like to inspect as an image. I am able to do this with gimp if I parse the data as an RGBA raw image with width 251 and height 261. However, I'd like to use Wolfram to do this programatically.

I have tried

Import["/path/to/my/raw/image.bin", {"RawBitMap", 
  "Summary"}, ImageSize -> 251]

which almost works. The issue is that it parses as an RGB file (without an alpha channel), and so the image is totally corrupted.

Question: Is this possible in Wolfram?

  • $\begingroup$ It's definitely possible, perhaps using BinaryReadList. It's hard to be more specific without an example file. $\endgroup$ Dec 12, 2020 at 22:28

1 Answer 1


This import format seems to be rather inflexible. The documentation, says,

Stores images as RGB or grayscale bitmaps at a resolution of 8 bits per channel.

Thus I would not bother with it.

Import as "Binary", use Partition to put the data into the desired form, then use Image to create the final image. I used something like this for a 150 by 150 image:

data = 
    Import["~/Downloads/r.rbm", "Binary"],
    {150, 150, 4}

Image[data, "Byte", ColorSpace -> "RGB"]
  • $\begingroup$ You could use ArrayReshape[data, {150,150,4}] instead of two partitions, and "ColorSpace"->"RGB" can be ColorSpace->"RGB" without the quotes around the option. $\endgroup$
    – flinty
    Dec 13, 2020 at 13:55
  • $\begingroup$ @flinty Thank you, this is much better. The answer is now updated. $\endgroup$
    – Szabolcs
    Dec 13, 2020 at 15:45
  • $\begingroup$ You can also use BinaryReadList for the first step to gain some speed. $\endgroup$
    – Roman
    Dec 13, 2020 at 16:43
  • $\begingroup$ @all: This question has morphed to a new one with more subtlety around the arguments: mathematica.stackexchange.com/questions/236640/… I was curious if you had any thoughts on it? $\endgroup$
    – George
    Dec 19, 2020 at 3:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.