# Importing a raw image

I have raw images that I can import and view with ImageJ. They are the output of a program which I don't have the source code for, so I'm stuck with the output format.

They are imported as follows with ImageJ:

Image type: 16 bit Unsigned

Width: 320

Height: 25600

Offset to fist image: 0 bytes

Number of images: 1

Gap Between images: 0 bytes

White is zero unchecked

Little-endian byte order unchecked

Open all files in folder unchecked

use virtual stack unchecked.

Essentially each raw file is a stack of 100 320 x 256 images.

When I try importing via "Import[]" in Mathematica, I get

LibraryFunction::rterr: An error with return code -2 was encountered evaluating the function ReadImageRAW.

Import::fmterr: Cannot import data as Raw format.

I can't seem to find any info on the first error message.

• Maybe the import filters "RawBitmap" or "BMP" with their various options may help. Have a look at their documentation. Since you do not provide example files, you have to try it on your own. – Henrik Schumacher Jan 10 '19 at 16:52
• Thanks for the response! I think RawBitmap is getting me closer, but it's giving me Import::coerr: Invalid setting ImageSize -> {320,25600}. – 2close2see Jan 10 '19 at 17:14
• You may also try Import[file, "UnsignedInteger16"] and convert it to an image with Image. – Henrik Schumacher Jan 10 '19 at 17:21
• BRILLIANT! "UnsignedInteger16" worked. Thanks so much....it entered everything as a list of all 8 million values so I'll have to do some massaging to get the formatting right, but that's a huge help. – 2close2see Jan 10 '19 at 17:34

images = Image /@ ArrayReshape[Import[file, "UnsignedInteger16"], {100, 256, 320}];

• I have not tested this but I believe that this (or a small variation of it) should do the trick. – Henrik Schumacher Jan 10 '19 at 17:41
• It looks like the width and height were switched, but the output doesn't look quite right. comparison with imageJ output Again, thanks so much for the help! – 2close2see Jan 10 '19 at 18:29
• images = Image /@ ArrayReshape[Import[file, "UnsignedInteger16"], {100, 256, 320}] ended up being the winner...thank you so much! – 2close2see Jan 10 '19 at 19:12
• You're welcome! – Henrik Schumacher Jan 10 '19 at 19:16