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 Jul 5, 2024
2 parents 6ffaad2 + 9c2da9c commit 582cdd8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions configs/digicam_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rpi:
hostname: null

# mask parameters
psf: null # if not provided, simulate with parameters below
mask:
fp: null # provide path, otherwise generate with seed
seed: 0
Expand Down
21 changes: 15 additions & 6 deletions scripts/measure/digicam_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
from lensless import ADMM
from lensless.utils.io import save_image
from lensless.hardware.trainable_mask import AdafruitLCD
from lensless.utils.io import load_image
from lensless.utils.io import load_image, load_psf
from lensless.utils.image import gamma_correction


@hydra.main(version_base=None, config_path="../../configs", config_name="digicam_example")
def digicam(config):
measurement_fp = config.capture.fp
psf_fp = config.psf
mask_fp = config.mask.fp
seed = config.mask.seed
rpi_username = config.rpi.username
Expand All @@ -43,7 +44,7 @@ def digicam(config):
np.random.seed(seed)
mask_vals = np.random.uniform(0, 1, mask_shape)

# simulate PSF
# create mask
mask = AdafruitLCD(
initial_vals=torch.from_numpy(mask_vals.astype(np.float32)),
sensor=capture_config["sensor"],
Expand All @@ -56,10 +57,20 @@ def digicam(config):
deadspace=simulation_config.get("deadspace", True),
# color_filter=color_filter,
)
psf = mask.get_psf().to(torch_device).detach()
psf_fp = "digicam_psf.png"

# use measured PSF or simulate
if psf_fp is not None:
psf = load_psf(
fp=to_absolute_path(psf_fp),
downsample=capture_config["down"],
flip=capture_config["flip"],
)
psf = torch.from_numpy(psf).type(torch.float32).to(torch_device)
else:
psf = mask.get_psf().to(torch_device).detach()
psf_np = psf[0].cpu().numpy()
psf_fp = "digicam_psf.png"

gamma = simulation_config.get("gamma", None)
if gamma is not None:
psf_np = psf_np / psf_np.max()
Expand All @@ -69,8 +80,6 @@ def digicam(config):
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

0 comments on commit 582cdd8

Please sign in to comment.