4
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$ Commented Jan 10, 2019 at 16:52
  • $\begingroup$ Thanks for the response! I think RawBitmap is getting me closer, but it's giving me Import::coerr: Invalid setting ImageSize -> {320,25600}. $\endgroup$
    – 2close2see
    Commented Jan 10, 2019 at 17:14
  • 2
    $\begingroup$ You may also try Import[file, "UnsignedInteger16"] and convert it to an image with Image. $\endgroup$ Commented Jan 10, 2019 at 17:21
  • $\begingroup$ 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. $\endgroup$
    – 2close2see
    Commented Jan 10, 2019 at 17:34

2 Answers 2

4
$\begingroup$
images = Image /@ ArrayReshape[Import[file, "UnsignedInteger16"], {100, 256, 320}];
$\endgroup$
4
  • $\begingroup$ I have not tested this but I believe that this (or a small variation of it) should do the trick. $\endgroup$ Commented Jan 10, 2019 at 17:41
  • 2
    $\begingroup$ 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! $\endgroup$
    – 2close2see
    Commented Jan 10, 2019 at 18:29
  • 1
    $\begingroup$ images = Image /@ ArrayReshape[Import[file, "UnsignedInteger16"], {100, 256, 320}] ended up being the winner...thank you so much! $\endgroup$
    – 2close2see
    Commented Jan 10, 2019 at 19:12
  • $\begingroup$ You're welcome! $\endgroup$ Commented Jan 10, 2019 at 19:16
2
$\begingroup$

After some dig in version 13, I found a package that can do this indeed. And I have tried Canon and Sony, so far so good.

<< ImageFileTools`

Here is a function ImageFileTools`Raw`RawGet, and its usage is:

? ImageFileTools`Raw`RawGet

enter image description here

Usage

enter image description here

$\endgroup$
1
  • $\begingroup$ I am trying it on a ARW file. I am getting the error: Failure["InitializationFailure", <|"MessageTemplate" -> "Failed to initialize.", "MessageParameters" -> <||>, "ErrorCode" -> -74, "Parameters" -> {"Raw::Reader::initializeLibRawObject: Failed to initialize LibRaw object"}|>] $\endgroup$
    – user13892
    Commented May 30 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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