Lytro Hack: How to extract data and jpg files from the .LFP file format using lfpsplitter

Lytro Hack: How to extract data from .LFP LightField Picture files (Picture: Lytro Raw camera extract, colour added) While Lytro’s desktop software is nice and easy to use, you may want to have a deeper look into the LightField Pictures you’ve created with your own Lytro LightField camera.
The first person to reverse-engineer the Lytro .LFP File Format and make the results available, was Nirmal Patel.

He also gives insight into the .LFP file format:

The file itself is formatted as follows. First, a header:

# magic 12 byte header (LFP)
89 4C 46 50 0D 0A 1A 0A 00 00 00 01
# 4 byte length (0, since there is nothing in this section)
00 00 00 00

After this are a number of sections.

The data in the first is plain text
JSON table of contents describing what the rest of the sections in the file
contain. The remaining sections can be additional metadata, a depth lookup
table, compressed jpg images, or raw sensor data depending on the file.

Patel created a commandline tool called lfpsplitter, which can extract the following data from .lfp and -stk.lfp files into individual files:

  • metadata
  • depth lookup table (plain-text list)
  • raw camera picture (.lfp)
  • component jpgs at different focal depths (-stk.lfp)

The source code of lfpsplitter is available in the lfptools project on GitHub.

How to compile lfptools:

You can compile the source code easily in cygwin (install it following this tutorial; make sure “gcc”, “gdb” and “make” are included. In the package selection process, click “View” in the top right, enter the names into the search field and click the rotating arrows until “bin” has an X):

  • Download the lfptools files and copy them to c:\cygwin\home\<username>.
  • Start cygwin and enter the following lines:
    gcc -O3 -Wall -c -o lfpsplitter.o lfpsplitter.c
    gcc -o lfpsplitter lfpsplitter.o -O3 -Wall
    (Important: They’re capital o’s, not zeros!)
  • When compiled successfully, you’ll find a new file named lfpsplitter.exe in that same directory.

Compile lfptools for your system using Cygwin

How to use lfptools in Windows:

  • Copy your compiled executable file to any location you like (in this example, we’ll use c:/lytro/)
  • Go to C:\cygwin\bin and copy cygwin1.dll to that same location
  • Add some LightField picture files (.lfp and -stk.lfp; they’re stored in C:\Users\<username>\AppData\Local\Lytro\images)
  • Start your Windows console (Win XP: Start – Run – cmd; Win7: Start, enter “cmd”, press Enter).
  • Go to the desired directory (e.g. “cd c:/lytro/”) and call it like this, depending on whether you’d like to extract raw data or just get the JPGs:
    lfpsplitter IMG_0001.lfp
    lfpsplitter IMG_0001-stk.lfp
  • lfptools will output metadata, depth lookup tables, and (1) the raw image file (when extracting from the full .lfp file) or (2) the different focal depth layers as JPGs (when extracting from a -stk.lfp file).

Run lfptools in your Windows console

lfptools output: Image stack files, raw file, metadata and depth lookup tables

The raw image file (IMG_0001_imageRef0.raw) can be converted to a black-and-white tif-file using the raw2tiff command, according to Patel’s article:
raw2tiff -w 3280 -l 3280 -d shortt IMG_0004_imageRef0.raw output.tif

Let me know how this works for you!

Be Sociable, Share!