Import Raw Images Using a C Library
LibRaw (http://www.libraw.org) is a library for reading RAW files obtained from digital photo cameras (CRW/CR2, NEF, RAF, DNG, and others). Import raw images into the Wolfram Language using libraw.
The function read_raw_image shown below takes a path to a file and returns an image expression. See the complete example here.
EXTERN_C DLLEXPORT int read_raw_image(WolframLibraryData libData, mint Argc,
MArgument *Args, MArgument res) {
...
WolframImageLibrary_Functions imgFuns = libData->imageLibraryFunctions;
...
file = MArgument_getUTF8String(Args[0]);
libraw_open_file(iprc, file);
libraw_unpack(iprc);
iprc->params.output_bps = 8;
...
img = libraw_dcraw_make_mem_image(iprc, &check);
...
if (img->bits == 16) {
raw_t_ubit16 * raw_data = (raw_t_ubit16*)img->data;
imgFuns->MImage_new2D(
img->width, img->height, 3,
MImage_Type_Bit16, MImage_CS_RGB, 1,
&out);
memcpy(imgFuns->MImage_getBit16Data(out),
raw_data,
img->width * img->height * 3 * sizeof(raw_t_ubit16));
} else { ... }
MArgument_setMImage(res, out);
...
}
Load the function and use it to import a raw file.
Out[1]= | |
Out[2]= | |
Out[3]= | |