# Dappled Photography: Mask Enhanced Cameras for Heterodyned Light Fields and Coded Aperture Refocusing

```Ashok Veeraraghavan, Ramesh Raskar, Amit Agrawal, Ankit Mohan and Jack TumblinACM SIGGRAPH 2007Low res pdf             High res pdfSlidesSIGGRAPH Talk SlidesFrequently Asked QuestionsMatlab Code for computing 4D Light Field from 2D ImageThe following code takes as input the 2D image captured by our heterodyne light field camera. It then computes the 4D light field from the captured 2D image.=======================================================================
% Source Code for Computing 4D Light-Field from Captured 2D Photo% Mask contains Cosines with 4 Harmonics leading to 9X9 Angular Samples```
m = 2133; n=1719 % Size of Captured Image

nAngles = 9; cAngles = (nAngles+1)/2;
% Number of Angular Samples

F1Y = 237;  F1X = 191;
%Cosine Frequency in Pixels from Calibration Image
phi1 = 300;  phi2 = 150; % PhaseShift due to Mask In-Plane Transltn wrt Sensor

F12X = floor(F1X/2); F12Y = floor(F1Y/2);

%Compute Spectral Tile Centers, Peak Strengths and Phase
for i=1:nAngles ;
for j=1:nAngles
CentY(i,j) = (m+1)/2 + (i-cAngles)*F1Y;CentX(i,j)  = (n+1)/2  + (j-cAngles)*F1X;
Mat(i,j) = exp(sqrt(-1)*((phi1*pi/180)*(i-cAngles) + (phi2*pi/180)*(j-cAngles)));
end
end

Mat(cAngles,cAngles) = Mat(cAngles,cAngles) * 20;

%Read Photo and Perform 2D FFT

%Rearrange Tiles of 2D FFT into 4D Planes to obtain FFT of 4D Light-Field
for i = 1: nAngles;
for j = 1: nAngles
FFT_LF(:,:,i,j) =  f(CentY(i,j)-F12Y:CentY(i,j)+F12Y,
CentX(i,j)-F12X:CentX(i,j)+F12X)/Mat(i,j);
end
end

LF     =    ifftn(ifftnshift(FFT_LF)); %Compute Light-Field by 4D Inverse FFT

%%%%End of Code
`=======================================================================`
`The complete Matlab code and input image can be download as a single zip file from here. The zip file also contains code for synthesizing 2D refocused images from the 4D light field.Code written in Matlab 7.4.0 (R2007a) on Windows XP.  Linux users should not have any problems.Note that the algorithm is based on FFT's. The code computes the FFT of 2D image (about 2000 by 2000 pixels), rearranges the 2D FFT into 4D and computes inverse 4D FFT. It may give 'insufficient memory' error on machines with RAM < 1GB. You can choose to run the code in gray scale to reduce computation and memory.`

`Graphical Illustration of the Matlab Code for Computing 4D Light Field from 2D PhotoConsider a scene consisting of several cones at different depths. If we take an image with a traditional camera, we get the photo shown above. The magnitudeof the 2D FFT of the image shows high energy at low frequencies. This is a well known fact that most energy in natural images is concentratedin low frequencies.Now consider taking a 2D photo of the same scene with our Heterodyne Light Field Camera. In this new camera, we place a cosine mask near thesensor. We get an image shown as below.Although this image looks similar to the previous photo captured using a traditional camera, notice the effect of mask on the input photo. The maskcasts a soft shadow on the sensor. It dapples the light reaching the sensor. In theory, mask modulates the incoming 4D light field to make spectralreplicas.Now consider the 2D FFT of this new image. Notice that the spectral replicas are clearly seen!!!.  Compare this FFT image with the previous FFT image to visualize the differences. These replicas are due to the cosine mask placed near the sensor. The cosine mask modulates the incoming 4D light field. In this example, the mask has 4 harmonics, or 4*2+1 = 9 impulses in its frequency response. Thus, we get 9*9=81 replicas in both x and y direction.Now lets see how we can obtain the 4D light field from the modulated 2D photo captured from our Heterodyne Light Field Camera. The entire algorithmis shown graphically below.Steps:1. Compute the 2D FFT of the captured 2D photo.2. We know that we will get 9*9 replicas due to the physical mask placed near the sensor. Rearrange these 81 tiles into 4D. 3. Compute the inverse 4D FFT to get the light field.Click on the above image to see a video (ViewCones1.avi) of different 'views' obtained from the light field. These views are essentially images that wewould obtain if we look through a narrow aperture on the lens at different positions.Email agrawal at merl dot com for questions/bugs etcBack to Dappled Photography.....`

Home