Skip to content

Commit

Permalink
Merge branch 'main' into measured_ambient
Browse files Browse the repository at this point in the history
  • Loading branch information
ebezzam committed Aug 21, 2024
2 parents e26ee45 + b439e08 commit 9d4cb6d
Show file tree
Hide file tree
Showing 10 changed files with 305 additions and 146 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Added

- Option to pass background image to ``utils.io.load_data``.
- Option to set image resolution with ``hardware.utils.display`` function.
- Add utility for mask adapter generation in ``lenseless.hardware.fabrication``
- Option to add simulated background in ``util.dataset``
- Auxiliary of reconstructing output from pre-processor (not working).
- Option to set focal range for MultiLensArray.
Expand Down Expand Up @@ -62,6 +63,7 @@ Added
- Fallback for normalization if data not in 8bit range (``lensless.utils.io.save_image``).
- Add utilities for fabricating masks with 3D printing (``lensless.hardware.fabrication``).
- WandB support.
- Script for Mask adapter generation and update new mount in doc

Changed
~~~~~~~
Expand Down
5 changes: 4 additions & 1 deletion configs/collect_dataset.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# python scripts/collect_dataset_on_device.py -cn collect_dataset

input_dir: /mnt/mirflickr/10
input_dir: /mnt/mirflickr/all
input_file_ext: jpg

# can pass existing folder to continue measurement
Expand Down Expand Up @@ -41,6 +41,9 @@ display:
landscape: False # whether to force landscape

capture:
measure_bg: False # measure bg every x images, set False if not measuring background
bg_fp: "black_background"
framerate: 10
skip: False # to test looping over displaying images
config_pause: 3
iso: 100
Expand Down
26 changes: 26 additions & 0 deletions configs/collect_dataset_background.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# python scripts/measure/collect_dataset_on_device.py -cn collect_dataset_background
defaults:
- collect_dataset
- _self_


output_dir: /mnt/mirflickr/all_measured_20240813-183259

# files to measure
n_files: 25000

min_level: 160
max_tries: 3


# -- display parameters
display:
screen_res: [1920, 1200] # width, height
image_res: [600, 600] # useful if input images don't have the same dimension, set it to this
vshift: -34

capture:
measure_bg: 1 # measure bg every x images, set False if not measuring background
awb_gains: [1.8, 1.1] # red, blue
fact_increase: 1.35 # multiplicative factor to increase exposure
fact_decrease: 1.3
4 changes: 2 additions & 2 deletions configs/upload_tapecam_mirflickr_ambient.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ defaults:
- _self_

repo_id: "Lensless/TapeCam-Mirflickr-Ambient"
n_files: null
n_files: 16000
test_size: 0.15
# -- to match TapeCam without ambient light
split: 100 # "first: first `nfiles*test_size` for test, `int`: test_size*split for test (interleaved) as if multimask with this many masks

lensless:
dir: data/100_samples
dir: /dev/shm/tape_15k_ambient/all_measured_20240805-143922
ambient: True
ext: ".png"

Expand Down
16 changes: 16 additions & 0 deletions docs/source/fabrication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
:alt: Mount components.
:align: center


Note that the most recent version of the mount looks like this, with the addition of stoppers,
to prevent the mask from scratching the Pi Camera.
This new version of the mount can be found `here <https://drive.switch.ch/index.php/s/QYH9vSqPd21DIHQ>`_

.. image:: mount_V4.png
:alt: New Inner Mount w/ Stopper.
:align: center

Mask3DModel
~~~~~~~~~~~
Expand All @@ -22,6 +30,14 @@
:members:
:special-members: __init__

Because newer versions of the masks' size are smaller, the following adapter enables
them to be used with the current mounts design.

.. image:: mask_adapter.png
:alt: Mask Adapter.
:align: center


MultiLensMold
~~~~~~~~~~~~~

Expand Down
Binary file added docs/source/mask_adapter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/mount_V4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 71 additions & 0 deletions lensless/hardware/fabrication.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,3 +520,74 @@ def generate(self, mask: np.ndarray, mask_size, depth: float) -> cq.Workplane:
)

return model


def create_mask_adapter(
fp, mask_w, mask_h, mask_d, adapter_w=12.90, adapter_h=9.90, support_w=0.4, support_d=0.4
):
"""
Create and store an adapter for a mask given its measurements.
Warning: Friction-fitted parts are to be made 0.05-0.1 mm smaller
(ex: mask's width must fit in adapter's, adapter's width must fit in mount's, ...)
Parameters
----------
fp : string
Folder in which to store the generated stl file.
mask_w : float
Length of the mask's width in mm.
mask_h : float
Length of the mask's height in mm.
mask_d : float
Thickness of the mask in mm.
adapter_w : float
Length of the adapter's width in mm.
default: current mount dim (13 - 0.1 mm)
adapter_h : float
Length of the adapter's height in mm.
default: current mount dim (1.5 - 0.1 mm)
support_w : float
Width of the small extrusion to support the mask in mm
default : current mount's dim (10 - 0.1 mm)
support_d : float
Thickness of the small extrusion to support the mask in mm
"""
epsilon = 0.2

# Make sure the dimension are realistic
assert mask_w < adapter_w - epsilon, "mask's width too big"
assert mask_h < adapter_h - epsilon, "mask's height too big"
assert mask_w - 2 * support_w > epsilon, "mask's support too big"
assert mask_h - 2 * support_w > epsilon, "mask's support too big"
assert os.path.exists(fp), "folder does not exist"

file_name = os.path.join(fp, "mask_adapter.stl")

# Prevent accidental overwrite
if os.path.isfile(file_name):
print("Warning: already find mask_adapter.stl at " + fp)
if input("Overwrite ? y/n") != "y":
print("Abort adapter generation.")
return

# Construct the outer layer of the mask
adapter = (
cq.Workplane("front")
.rect(adapter_w, adapter_h)
.rect(mask_w, mask_h)
.extrude(mask_d + support_d)
)

# Construct the dent to keep the mask secure
support = (
cq.Workplane("front")
.rect(mask_w, mask_h)
.rect(mask_w - 2 * support_w, mask_h - 2 * support_w)
.extrude(support_d)
)

# Join the 2 shape in one
adapter = adapter.union(support)

# Save into path
cq.exporters.export(adapter, file_name)
Loading

0 comments on commit 9d4cb6d

Please sign in to comment.