Skip to content

Commit ee65552

Browse files
committed
Merge.
2 parents ad2387a + 5c7f81c commit ee65552

File tree

12 files changed

+302
-90
lines changed

12 files changed

+302
-90
lines changed

.github/workflows/python_no_pycsou.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
run: |
4343
pip install flake8
4444
# stop the build if there are Python syntax errors or undefined names
45-
flake8 . --count --select=B,C,E,F,W,T4,B9 --show-source --statistics --max-complexity=18 --max-line-length=100 --ignore=E203,E266,E501,W503,F403,F401,C901 --exclude=profile,scripts,docs
45+
flake8 . --count --select=B,C,E,F,W,T4,B9 --show-source --statistics --max-complexity=18 --max-line-length=100 --ignore=E203,E266,E501,W503,F403,F401,C901,PLW0602 --exclude=profile,scripts,docs
4646
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
4747
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
4848
- name: Format with black

.github/workflows/python_pycsou.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
run: |
4343
pip install flake8
4444
# stop the build if there are Python syntax errors or undefined names
45-
flake8 . --count --select=B,C,E,F,W,T4,B9 --show-source --statistics --max-complexity=18 --max-line-length=100 --ignore=E203,E266,E501,W503,F403,F401,C901 --exclude=profile,scripts,docs
45+
flake8 . --count --select=B,C,E,F,W,T4,B9 --show-source --statistics --max-complexity=18 --max-line-length=100 --ignore=E203,E266,E501,W503,F403,F401,C901,PLW0602 --exclude=profile,scripts,docs
4646
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
4747
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
4848
- name: Format with black

configs/benchmark/diffusercam.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ huggingface:
2020
single_channel_psf: True
2121

2222
algorithms: [
23-
# "ADMM",
23+
"ADMM",
24+
"ADMM_PnP",
25+
"FISTA",
26+
"FISTA_PnP",
2427

2528
## -- reconstructions trained on DiffuserCam measured
2629
# "hf:diffusercam:mirflickr:U5+Unet8M",
@@ -39,7 +42,7 @@ algorithms: [
3942
# "hf:diffusercam:mirflickr:Transformer4M+U5+Transformer4M",
4043
# "hf:diffusercam:mirflickr:Transformer4M+U5+Transformer4M_psfNN",
4144
# "hf:diffusercam:mirflickr:U5+Transformer8M",
42-
"hf:diffusercam:mirflickr:U5+Unet8M_adamw",
45+
# "hf:diffusercam:mirflickr:U5+Unet8M_adamw",
4346
# "hf:diffusercam:mirflickr:Unet4M+U5+Unet4M_adamw",
4447
# "hf:diffusercam:mirflickr:Unet4M+U5+Unet4M_psfNN_adamw",
4548

@@ -84,6 +87,8 @@ algorithms: [
8487
# "hf:digicam:mirflickr_multi_25k:Unet4M+U5+Unet4M_wave",
8588
]
8689

87-
save_idx: [0, 1, 3, 4, 8, 45, 58, 63]
88-
n_iter_range: [100] # for ADMM
90+
save_idx: [0, 1, 3, 4, 8]
91+
n_iter_range: [10] # for ADMM
92+
# save_idx: [0, 1, 3, 4, 8, 45, 58, 63]
93+
# n_iter_range: [100] # for ADMM
8994

configs/benchmark/digicam.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@ huggingface:
2323

2424
algorithms: [
2525
# "ADMM",
26+
"ADMM",
27+
"ADMM_PnP",
2628

2729
# # -- reconstructions trained on measured data
28-
"hf:digicam:mirflickr_single_25k:U5+Unet8M_wave",
30+
# "hf:digicam:mirflickr_single_25k:U5+Unet8M_wave",
2931
# "hf:digicam:mirflickr_single_25k:Unet8M+U5_wave",
3032
# "hf:digicam:mirflickr_single_25k:TrainInv+Unet8M_wave",
3133
# "hf:digicam:mirflickr_single_25k:MMCN4M+Unet4M_wave",
3234
# "hf:digicam:mirflickr_single_25k:MWDN8M_wave",
3335
# "hf:digicam:mirflickr_single_25k:Unet4M+TrainInv+Unet4M_wave",
34-
"hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave",
36+
# "hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave",
3537
# "hf:digicam:mirflickr_single_25k:Unet2M+MMCN+Unet2M_wave",
3638
# "hf:digicam:mirflickr_single_25k:Unet2M+MWDN6M_wave",
3739
# "hf:digicam:mirflickr_single_25k:Unet4M+U10+Unet4M_wave",
38-
"hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave_psfNN",
40+
# "hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave_psfNN",
3941
# "hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave_flips",
4042
# "hf:digicam:mirflickr_single_25k:Unet4M+U5+Unet4M_wave_flips_rotate10",
4143
# "hf:digicam:mirflickr_single_25k:Unet8M_wave_v2",
@@ -53,8 +55,10 @@ algorithms: [
5355
# "hf:diffusercam:mirflickr:Unet4M+U5+Unet4M_psfNN",
5456
]
5557

56-
save_idx: [1, 2, 4, 5, 9, 24, 33, 61]
57-
n_iter_range: [100] # for ADMM
58+
# save_idx: [1, 2, 4, 5, 9, 24, 33, 61]
59+
# n_iter_range: [100] # for ADMM
60+
save_idx: [1, 2, 4, 5, 9]
61+
n_iter_range: [10] # for ADMM
5862

5963
# simulating PSF
6064
simulation:

configs/demo_icassp2025.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ defaults:
66
gamma: 2.2 # for plotting PSF
77

88
display:
9-
image_res: [-1,1100] # negative value to set according to other dimension
9+
image_res: [900,-1] # negative value to set according to other dimension
1010
vshift: -26
1111

1212
capture:
1313
legacy: True
1414
bayer: True
1515
rgb: True
1616
down: 4
17-
awb_gains: [2.0, 1.1]
17+
awb_gains: [1.8, 1.1]
1818

1919
recon:
2020
gamma: null
2121
downsample: 4
2222
dtype: float32
2323
use_torch: True
2424
torch_device: cuda:0
25-
algo: admm
25+
algo: fista
2626

2727
fista:
2828
n_iter: 300
@@ -33,5 +33,5 @@ recon:
3333
postproc:
3434
# crop in percent to extract region of interest
3535
# set to null to skip
36-
crop_hor: [0.3, 0.75]
37-
crop_vert: [0.22, 0.7]
36+
crop_hor: [0.29, 0.67]
37+
crop_vert: [0.22, 0.78]

configs/telegram_demo_icassp2025.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ psf:
1515
fp: psf_voronoi_apr2025/voronoi_rgb.png
1616
downsample: 4
1717

18+
default_algo: fista
19+
1820
files:
1921
mnist:
2022
fp: data/original/mnist_3.png
@@ -32,4 +34,18 @@ files:
3234
fp: data/original/tree.png
3335
exposure: 0.08
3436
brightness: 100
35-
37+
38+
overlay:
39+
alpha: 60
40+
41+
img1:
42+
fp: data/original/epfl_white.png
43+
scaling: 0.23
44+
position: [5,15]
45+
46+
img2:
47+
fp: data/original/icassp.png
48+
scaling: 0.2
49+
position: [305,10]
50+
51+
img3: null

lensless/recon/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,12 @@ def apply_denoiser(
307307
noise_level = noise_level / 255.0
308308
else:
309309
noise_level = torch.tensor([noise_level / 255.0])
310-
311310
image = torch.cat(
312311
(
313312
image,
314-
noise_level.repeat(image.shape[0], 1, image.shape[2], image.shape[3]),
313+
noise_level.repeat(image.shape[0], 1, image.shape[2], image.shape[3]).to(
314+
image.device
315+
),
315316
),
316317
dim=1,
317318
)
@@ -633,7 +634,7 @@ def __init__(
633634
Epoch at which to unfreeze post process component. Default is None.
634635
635636
"""
636-
global print
637+
# global print
637638

638639
self.use_wandb = use_wandb
639640

lensless/utils/dataset.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def natural_sort(arr):
101101
# DigiCam MirFlickr Mini (472 MB) https://huggingface.co/datasets/bezzam/DigiCam-Mirflickr-SingleMask-1K
102102
"digicam_mirflickr_mini": {
103103
"size (GB)": 0.472,
104-
"huggingface_repo": "bezzam/DigiCam-Mirflickr-SingleMask-25K",
104+
"huggingface_repo": "bezzam/DigiCam-Mirflickr-SingleMask-1K",
105105
"display_res": [900, 1200],
106106
"rotate": True,
107107
"alignment": {"top_left": [80, 100], "height": 200},
@@ -138,6 +138,29 @@ def natural_sort(arr):
138138
"display_res": [600, 600],
139139
"alignment": {"top_left": [118, 220], "height": 123},
140140
},
141+
# Multilens MirFlickr Mini (427 MB) https://huggingface.co/datasets/Lensless/mirflickr_voronoi_1k
142+
"multilens_mirflickr_mini": {
143+
"size (GB)": 0.427,
144+
"huggingface_repo": "Lensless/mirflickr_voronoi_1k",
145+
"psf": "psf_measured.png",
146+
"display_res": [900, 1200],
147+
},
148+
# Coded Aperture (MLS) MirFlickr 1K (467 MB) https://huggingface.co/datasets/Lensless/mirflickr_CA_fine_1k
149+
"mls_mirflickr_1k": {
150+
"size (GB)": 0.467,
151+
"huggingface_repo": "Lensless/mirflickr_CA_fine_1k",
152+
"psf": "psf_measured.png",
153+
"display_res": [900, 1200],
154+
# "alignment": {"top_left": [118, 220], "height": 123},
155+
},
156+
# Fresnel Zone Aperture MirFlickr 1K (454 MB) https://huggingface.co/datasets/Lensless/Mirflickr_FZA_fine_1k
157+
"fza_mirflickr_1k": {
158+
"size (GB)": 0.454,
159+
"huggingface_repo": "Lensless/Mirflickr_FZA_fine_1k",
160+
"psf": "psf_measured.png",
161+
"display_res": [900, 1200],
162+
# "alignment": {"top_left": [118, 220], "height": 123},
163+
},
141164
}
142165

143166

lensless/utils/plot.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,27 @@ def plot_cross_section(
235235
zero_crossings = np.where(np.diff(np.signbit(cross_section + plot_db_drop)))[0]
236236
if len(zero_crossings) >= 2:
237237
zero_crossings -= np.argmax(cross_section)
238+
<<<<<<< HEAD
238239
width = zero_crossings[-1] - zero_crossings[0]
239240
ax.set_title(f"-{plot_db_drop}dB width = {width}")
240241
ax.axvline(x=zero_crossings[0], c="k", linestyle="--")
241242
ax.axvline(x=zero_crossings[-1], c="k", linestyle="--")
242243
print(f"{plot_db_drop}dB width : {width} pixels")
244+
=======
245+
246+
# width = zero_crossings[-1] - zero_crossings[0]
247+
# ax.axvline(x=zero_crossings[0], c="k", linestyle="--")
248+
# ax.axvline(x=zero_crossings[-1], c="k", linestyle="--")
249+
250+
first_crossing = np.abs(zero_crossings[np.argmin(np.abs(zero_crossings))])
251+
width = 2 * np.abs(first_crossing)
252+
ax.axvline(x=-first_crossing, c="k", linestyle="--")
253+
ax.axvline(x=+first_crossing, c="k", linestyle="--")
254+
255+
ax.set_title("Cross-section")
256+
ax.set_xlabel(f"-{plot_db_drop}dB width = {width}")
257+
258+
>>>>>>> main
243259
else:
244260
warnings.warn(
245261
"Width could not be determined. Did not detect two -{} points : {}".format(
@@ -291,7 +307,7 @@ def plot_autocorr2d(vals, pad_mode="reflect", ax=None):
291307
return ax, autocorr
292308

293309

294-
def plot_autocorr_rgb(img, width=3, figsize=None):
310+
def plot_autocorr_rgb(img, width=3, figsize=None, plot_psf=False, psf_gamma=2.2):
295311
"""
296312
Plot autocorrelation of each channel of an image.
297313
@@ -307,15 +323,36 @@ def plot_autocorr_rgb(img, width=3, figsize=None):
307323
assert len(img.shape) == 3, "Image must be 3D"
308324
assert img.shape[2] == 3, "Image must have 3 color channels"
309325

310-
_, ax_auto = plt.subplots(ncols=3, nrows=2, num="Autocorrelations", figsize=figsize)
311-
312-
for i, c in enumerate(["r", "g", "b"]):
313-
_, autocorr_c = plot_autocorr2d(img[:, :, i], ax=ax_auto[0][i])
326+
if plot_psf:
327+
_, ax_auto = plt.subplots(ncols=3, nrows=3, num="Autocorrelations", figsize=figsize)
328+
else:
329+
_, ax_auto = plt.subplots(ncols=3, nrows=2, num="Autocorrelations", figsize=figsize)
330+
331+
for i, c in enumerate(["Red", "Green", "Blue"]):
332+
if plot_psf:
333+
plot_image(
334+
img[:, :, i],
335+
ax=ax_auto[0][i],
336+
gamma=psf_gamma,
337+
normalize=True,
338+
)
339+
# ax_auto[0][i].imshow(img[:, :, i], cmap="gray")
340+
ax_auto[0][i].axis("off")
341+
ax_auto[0][i].set_title(f"{c} PSF")
342+
343+
# plot autocorrelation
344+
_, autocorr_c = plot_autocorr2d(img[:, :, i], ax=ax_auto[1 if plot_psf else 0][i])
345+
ax_auto[1][i].set_title("Autocorrelation")
346+
# # -- horizontal cross-section
347+
max_idx = np.unravel_index(np.argmax(autocorr_c, axis=None), autocorr_c.shape)
348+
idx = max_idx[0]
349+
# ax_auto[1][i].axhline(y=idx, c=c, linestyle="--")
314350

315351
ax, _ = plot_cross_section(
316352
autocorr_c,
353+
idx=idx,
317354
color=c,
318-
ax=ax_auto[1][i],
355+
ax=ax_auto[2 if plot_psf else 1][i],
319356
plot_db_drop=width,
320357
)
321358
if i != 0:

notebook/lenslesspicam_demo.ipynb

Lines changed: 166 additions & 37 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)