Skip to content

Commit

Permalink
Merge branch 'expose_sim_param' of github.com:LCAV/LenslessPiCam into…
Browse files Browse the repository at this point in the history
… expose_sim_param
  • Loading branch information
ebezzam committed May 27, 2024
2 parents a111135 + 6204ff4 commit 75719e6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion configs/benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ simulation:
# mask2sensor: 9e-3 # mask2sensor: 4e-3
# -- for CelebA
scene2mask: 0.25 # [m]
mask2sensor: 0.002 # [m]
mask2sensor: 0.002 # [m]
deadspace: True # whether to account for deadspace for programmable mask
# see waveprop.devices
use_waveprop: False # for PSF simulation
sensor: "rpi_hq"
Expand Down
11 changes: 10 additions & 1 deletion configs/digicam_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ rpi:
mask:
fp: null # provide path, otherwise generate with seed
seed: 0
# defaults to configuration use for this dataset: https://huggingface.co/datasets/bezzam/DigiCam-Mirflickr-SingleMask-25K
# ie this config: configs/collect_mirflickr_singlemask.yaml
shape: [54, 26]
center: [57, 77]

Expand All @@ -37,4 +39,11 @@ capture:
# reconstruction parameters
recon:
torch_device: 'cpu'
n_iter: 100 # number of iterations of ADMM
n_iter: 100 # number of iterations of ADMM

simulation:
use_waveprop: True
deadspace: True
scene2mask: 0.3
mask2sensor: 0.002
gamma: null # just for saving
17 changes: 16 additions & 1 deletion scripts/measure/digicam_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from lensless.utils.io import save_image
from lensless.hardware.trainable_mask import AdafruitLCD
from lensless.utils.io import load_image
from lensless.utils.image import gamma_correction


@hydra.main(version_base=None, config_path="../../configs", config_name="digicam_example")
Expand All @@ -32,6 +33,7 @@ def digicam(config):
mask_center = config.mask.center
torch_device = config.recon.torch_device
capture_config = config.capture
simulation_config = config.simulation

# load mask
if mask_fp is not None:
Expand All @@ -48,14 +50,27 @@ def digicam(config):
slm="adafruit",
downsample=capture_config["down"],
flipud=capture_config["flip"],
use_waveprop=simulation_config.get("use_waveprop", False),
scene2mask=simulation_config.get("scene2mask", None),
mask2sensor=simulation_config.get("mask2sensor", None),
deadspace=simulation_config.get("deadspace", True),
# color_filter=color_filter,
)
psf = mask.get_psf().to(torch_device).detach()
psf_fp = "digicam_psf.png"
save_image(psf[0].cpu().numpy(), psf_fp)

psf_np = psf[0].cpu().numpy()
gamma = simulation_config.get("gamma", None)
if gamma is not None:
psf_np = psf_np / psf_np.max()
psf_np = gamma_correction(psf_np, gamma=gamma)

save_image(psf_np, psf_fp)
print(f"PSF shape: {psf.shape}")
print(f"PSF saved to {psf_fp}")

raise ValueError

if measurement_fp is not None:
# load image
img = load_image(
Expand Down
1 change: 0 additions & 1 deletion scripts/sim/digicam_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ def digicam_psf(config):
# plot overlayed
fp = os.path.join(output_folder, "psf_overlay.png")
psf_meas_norm = psf_meas[0] / np.max(psf_meas)
# psf_meas_norm = gamma_correction(psf_meas_norm, gamma=config.digicam.gamma)
psf_in_np_norm = psf_in_np / np.max(psf_in_np)

plt.figure()
Expand Down

0 comments on commit 75719e6

Please sign in to comment.