About the viewer

The flash light field viewer used in the light field archive, and this document, were written by Andrew Adams.

The viewer was written in flex/actionscript using the free flex 3.0 sdk from Adobe.

The viewer source and binary are available here: aperture.zip

Using the viewer for your own light fields

The URLS the viewer uses look something like this:


If you go ahead and download one of those zip files (such as this one of jelly beans). You'll see that they contain a large number of jpeg files, a single xml file, and sometimes a depth map called depth.png. Don't worry about the depth map for now.

The jpegs are the subaperture views. They are rectified views of the scene from many different directions. For the light fields here, I've encoded the filenames to include the position they were taken from (refered to as the (u, v) coordinates), but this is not necessary - the xml file will specify the (u, v) coordinates.

The xml file looks something like this:

<subaperture src="subapertureview_1.jpg" u="123.4" v="567.8" />
<subaperture src="subapertureview_2.jpg" u="999.2" v="-56" />
<subaperture src="subapertureview_3.jpg" u="9.9" v="0" />

So, to make your own .zip file that will work with the viewer, create an xml file like the one above. It doesn't matter what it's called - the viewer just looks for a file that ends in xml. Remember that xml is more strict that html. You need to close every tag and put every attribute inside quotes. Next, put the xml file and all the subaperture images inside a zip file together. It's probably best not to use any directory structure inside the zip file.

The final step is to inject a special checksum into the zip file to keep the third-party zip-file-handling library I use happy. Aperture.zip, linked above, includes fzip-prepare.py which is a python script that does this:

python fzip-prepare.py myzipfile.zip

You can now view your light field locally using a URI like this:

file:///C:/(some directory)/aperture_local.swf?lightfield=(some relative path)/myzipfile.zip&zoom=1

Or you can put it on a web page like so:

http://(some server)/(some directory)/aperture.swf?lightfield=(some relative path)/myzipfile.zip&zoom=1

Incorporating Depth Maps for Autofocus

The depth maps I use encode depth as disparity, with a certain scale and offset. Here's the procedure you should use to calculate a depth map in a way that the viewer can handle:

  1. Shift all the (u, v) coordinates of the subaperture views so that their centroid is (0, 0) (ie subtract the average (u, v) coordinate)
  2. Apply a uniform scale to the (u, v) coordinates so that all coordinates lie between -0.9 and +0.9. It's very important that the scale is uniform, or the focus will become astigmatic.
  3. At each pixel (x, y), compute the best value alpha, such that when you translate each image by (alpha*u, alpha*v) all the images match in a local neighbourhood around position (x, y) (depth from stereo). Alternatively, check if the sum of the same neighbourhoods contains sharp features (depth from focus).
  4. Round alpha to the nearest integer, add 128, and store them all in an image called depth.png. Other names are OK too provided your xml file refers to the right file. Your depth map should be the same resolution as each subaperture view, and it should be grayscale.
  5. Open your depth map in photoshop and clean it up a little if you like. One thing I like to do is compute both an alpha value and a confidence, and do a weighted blur of the image using the confidence values as the weights.

Finally, modify your xml file to refer to the computed depth map, and include it in your zip archive.

<lightfield depth="depth.png">
<subaperture src="subapertureview_1.jpg" u="123.4" v="567.8" />
<subaperture src="subapertureview_2.jpg" u="999.2" v="-56" />
<subaperture src="subapertureview_3.jpg" u="9.9" v="0" />

Fixing the range of the focus slider

Depending on where your reference plane was, and how much parallax you had, the focus slider may have fairly useless bounds. It defaults to +/-50 in the disparity space descibed above. To change these bounds, modify your xml file like so:

<lightfield fmin="-200" fmax="200">
<subaperture src="subapertureview_1.jpg" u="123.4" v="567.8" />
<subaperture src="subapertureview_2.jpg" u="999.2" v="-56" />
<subaperture src="subapertureview_3.jpg" u="9.9" v="0" />

Changing the focal range like this doesn't play that well with including a depth map. You can do both, provided that fmax < 127, and fmin = -fmax.

Modifying the viewer

Feel free to do whatever you want with the viewer. If you do something cool with it, I'd love to hear about it.

To compile the viewer, ensure that the flex compiler mxmlc is in your path, and issue the command:

mxmlc -system.include-libraries=fzip.swc aperture.mxml

To compile the viewer for local use (ie using file:/// URIs instead of web addresses), add the following flag:

mxmlc -system.include-libraries=fzip.swc aperture.mxml --use-network=false

The viewer also uses a third party zip-file-handling class library called fzip. You don't need to download anything extra - a binary is included in the zip file above.

Software License

The source code for the viewer is covered by our Stanford Computer Graphics Laboratory General Software License, which is basically the BSD license, and is very permissive. FZip is redistributable under the zlib license, which is also very permissive. Have fun!

© 2008 Stanford Graphics Laboratory
Created by Vaibhav Vaish. Updated by Andrew Adams.
Last update: June 5, 2009 08:04:11 AM