File Exchange

image thumbnail

RAW Camera File Reader

version (108 KB) by Bryan White
Functions to read raw images from many digital cameras into MATLAB.


Updated 06 Jan 2020

View License

These functions will read raw images from many digital cameras into MATLAB.The reader function, READRAWC, is a C MEX-file implementation of Dave Coffin's dcraw.c program (version 1.194) from:

Cite As

Bryan White (2020). RAW Camera File Reader (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (20)


I can't compile it either using r2020a, also it sadly is very outdated!

Olatunji Omisore

I am trying to use this program to read a raw image, but I am having this issue:

Undefined function or variable 'readrawc'.

Error in israw (line 12)
result = readrawc(filename,s);

Error in readraw (line 68)
if ~israw(filename)

Please, kindly help!

Tom Rockett

Can't compile the readrawc.c mex file, using MingW64 compiler. Any ideas?

Error using mex
C:\Users\sirro\AppData\Local\Temp\mex_614190249922623_14516\readrawc.obj:readrawc.c:(.text+0xdc0): undefined reference to `__imp_ntohs'
C:\Users\sirro\AppData\Local\Temp\mex_614190249922623_14516\readrawc.obj:readrawc.c:(.text+0xea4): undefined reference to `__imp_ntohs'
C:\Users\sirro\AppData\Local\Temp\mex_614190249922623_14516\readrawc.obj:readrawc.c:(.text+0x1051): undefined reference to `__imp_ntohs'
C:\Users\sirro\AppData\Local\Temp\mex_614190249922623_14516\readrawc.obj:readrawc.c:(.text+0x2057): undefined reference to `__imp_ntohs'
C:\Users\sirro\AppData\Local\Temp\mex_614190249922623_14516\readrawc.obj:readrawc.c:(.text+0x37a9): undefined reference to `__imp_ntohs'
C:\Users\sirro\AppData\Local\Temp\mex_614190249922623_14516\readrawc.obj:readrawc.c:(.text+0x3dc8): more undefined references to `__imp_ntohs'
C:\Users\sirro\AppData\Local\Temp\mex_614190249922623_14516\readrawc.obj:readrawc.c:(.text+0x4c55): undefined reference to `__imp_htonl'
C:\Users\sirro\AppData\Local\Temp\mex_614190249922623_14516\readrawc.obj:readrawc.c:(.text+0x4df0): undefined reference to `__imp_ntohs'
C:\Users\sirro\AppData\Local\Temp\mex_614190249922623_14516\readrawc.obj:readrawc.c:(.text+0xc82a): undefined reference to `__imp_htonl'
C:\Users\sirro\AppData\Local\Temp\mex_614190249922623_14516\readrawc.obj:readrawc.c:(.text+0xc90d): undefined reference to `__imp_htons'
collect2.exe: error: ld returned 1 exit status

Enrico Segre

This is using code from dcraw 1.194, Vendor's Date: 2004/05/22. Dcraw is by now at 1.478, Date: 2018/06/01. Many things have changed since then... for one .nef files which I can't read meaningfully either. The C code is over 4000 lines here vs 10500 lines there, which makes merging a daunting task even for someone dedicated. It's a problew with dcraw itself, by design not provided as a library. Perhaps a binding to would have better chances to stay viable for longer, even thought both are single-developer projects.

Daryl Chulho

I'd like to ask the same question as chang ardour did. Does it work for .nef files? I included .nef in rawFormat.ext to see what happens. Can anyone confirm if it works with .nef?

Raissel Ramirez

After loading .NEF images, the result is an image from a different size than the original and looking somehow redish or pinky... I don't know what I'm doing wrong, there is any working example somewhere?


Haven't used it yet so I can't rate it, but just wanted to comment on the compilation of the C file using mex - you need to make sure you link with libjpeg. Assuming you have libjpeg installed, you should be able to do:

mex -ljpeg readrawc.c

That allowed me to compile with lots of warnings but no errors.


why I can't compile the readrawc.c MEX-file,it has so mang errors.

Royi Avital

What's the output? Is it an Image after Demosaicing?
Is there an option to get the original bayer matrices?


Ryan Taylor

No idea whether the conversion takes the camera's ICC profile into account (and there appears no way to find out). This is extremely problematic if you want to do any accurate analysis of your images....

Kurt William

This older version, I was wondering when the newer version would be uploaded. thanks

Ehsan Azarnasab

Thanks, Good starting point for applying different filters, and techniques of photo bracketing in an environment which is more convenient to me.

Ehsan Azarnasab

Thanks, Good starting point for applying different filters, and techniques of photo bracketing in an environment which is more convenient to me.

Steffen Skopp

This code is based on an older version of dcraw.
I am trying some things, newer version of dcraw, documentmode and more - but still under development.

S. Skopp

Works on Mac OSX 10.5. as well. GREAT !

Only one little change to make. The compiled file was named to "-DWIN32.mexmaci", must change to "readrawc.mexmaci".

jack chan

Rick Sampson

How about *.cr2? Doesn't seem to be compatable with this, only CRW.

Lys Elisabeth

chang ardour

Does it support .NEF file?

Uwe Artmann

That's what i was looking for.


Updated link to Dave Coffin's website.

Updated license

Removed "readme.m.bak", which was inadvertently and unnecessarily included in previous submission.

Exceedingly minor update -- fixed compilation code in readme.m help, which had switched the Windows and Unix MEX commands.

MATLAB Release Compatibility
Created with R14SP1
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: matlab-unpackRaw, Read RAW camera images