This software is a part of supplementary material of a CVPR2024 paper: 

    Shuji Habuchi, Keita Takahashi, Chihiro Tsutake, Toshiaki Fujii, Hajime Nagahara: 
    "Time-Efficient Light-Field Acquisition Using Coded Aperture and Events", 
    IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) 2024.

When you use the codes for research purpose, please include citation to the above paper in your written documents and presentations.

-----------------------------------------------------
The software can reconstruct a light field from a computer generated scene (Planets, provided by Sakai et al. [1]) and real-world scenes (Chess, Fish) using our pre-trained network weights (Flexible-tau model).

    [1] Kohei Sakai, Keita Takahashi, Toshiaki Fujii, and Hajime Nagahara: 
    "Acquiring dynamic light fields through coded aperture camera",
    In European Conference on Computer Vision, pages 368-385, 2020.


Requirement
-----------------------------------------------------
The included software requires PyTorch (version 2.0.0), CUDA (version 11.7).
We tested the software on Ubuntu 20.04.6 LTS with Python 3.8.10. Our python environment is shown in the requirements.txt.


Usage
-----------------------------------------------------
1. Installation

To install the dependencies, run:

    > pip3 install torch==2.0.0+cu117 -f https://download.pytorch.org/whl/torch_stable.html
    > pip3 install -r requirements.txt


2. Run the test from a light field

We include a light field (8x8 views) for 1 scene (Planets), which are located at:
    - LF_data/8x8/Povray/Planets/

To obtain an image frame and event stacks from the light field and reconstruct light field from them, execute "test_from_LF.py" as follows.
    > python3 test_from_LF.py --test_threshold [tau]

Here, [tau] is the contrast threshold for events. we used [tau] = 0.075/0.15/0.3 for evaluation.

The outputs are stored as follows.
    - Flexible-tau_pretrained/test/from_LF_data/test_threshold_[tau]/Povray/Planets/acquired_data : acquired (observed) image frame and event stacks
    - Flexible-tau_pretrained/test/from_LF_data/test_threshold_[tau]/Povray/Planets/gt_views : ground truth
    - Flexible-tau_pretrained/test/from_LF_data/test_threshold_[tau]/Povray/Planets/re_views : reconstructed light field (8x8 views)


3. Run the test from acquired data

We also include acquired data for 3 scenes (Planets, Chess, Fish), which are located at:
    - Acquired_data/Planets (computer generated)
    - Acquired_data/Chess (obtained from our prototype camera)
    - Acquired_data/Fish (obtained from our prototype camera)

Each folder contains the following:
    - 1 image frame (image_frame.png)
    - 3 event stacks (event_stack_00000.npy, event_stack_00001.npy, event_stack_00002.npy)
    - 3 visualized event stacks (event_stack_vis_00000.png, event_stack_vis_00001.png, event_stack_vis_00002.png)

To reconstruct light field (8x8 views) from acquired data, execute "test_from_acquired_data.py" as follows.
    > python3 test_from_acquired_data.py

The outputs are stored as follows.
    - Flexible-tau_pretrained/test/from_acquired_data/Planets
    - Flexible-tau_pretrained/test/from_acquired_data/Chess
    - Flexible-tau_pretrained/test/from_acquired_data/Fish


-----------------------------------------
## License
-----------------------------------------
The MIT License (MIT)

Copyright (c) 2024 Shuji Habuchi at Fujii Lab. of Nagoya University

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
