Code covered by the BSD License  

Highlights from
deprecated -- Light Field Toolbox v0.2 -- v0.3 now available

image thumbnail

deprecated -- Light Field Toolbox v0.2 -- v0.3 now available


Donald Dansereau


26 Apr 2013 (Updated )

A set of tools for working with light field (aka plenoptic) imagery in Matlab

LFReadRaw( Fname, ImgSize )
% LFReadRaw - reads the Lytro `RAW' file format, as output by the `LFP Reader' tool
% Usage:
%     Img = LFReadRaw( Fname )
%     Img = LFReadRaw( Fname, ImgSize )
% There is no universal `RAW' file format. This function reads 12-bit packed raw files, outputting
% an array of type uint16. This is the format utilized by Lytro to store raw lenselet images for
% photos and white images for calibration data. However, some LFP tools convert these raw files
% during unpacking, and so when using a tool other than LFP Reader v2.0.0, the resulting RAW files
% may be incompatible with this function. Generally minor modification will accommodate other
% formats.
% Note that reading a packed 12-bit raw files using fread is appreciably slower than reading a .png
% or .tiff using imread, so as an optimization in scenarios where a file is likely to be read many
% times one might consider converting raw images using an external tool, such as the cross-platform
% ImageMagick tool.
% Inputs :
%     Fname : path to the 12-bit packed raw file to read
%     [optional] ImgSize : a 2D vector defining the size of the image, in pixels. The default value
%     of [3280,3280] corresponds to the size of Lytro images.
% Outputs:
%     Img is an array of uint16 gray levels. No demosaicing (decoding Bayer pattern) is performed.
%     To demosaic, try:
%         Img = demosaic(Img, 'bggr');
% See also: LFDecodeLenseletImageSimple, demosaic

% Part of LF Toolbox v0.2 released 27-May-2013
% Copyright (c) 2013, Donald G. Dansereau

function Img = LFReadRaw( Fname, ImgSize )

ImgSize = LFDefaultVal( 'ImgSize', [3280,3280] );

%---Read the file---
f = fopen( Fname );
Img = fread( f, ImgSize, 'ubit12=>uint16', 0, 'b' )';  % note the ' is necessary to get the rotation right
fclose( f );

Contact us