Skip to content

Commit 8d4c7e7

Browse files
committed
Merge branch 'update_demo' into icassp_demo
2 parents 2976bae + b828828 commit 8d4c7e7

File tree

3 files changed

+184
-44
lines changed

3 files changed

+184
-44
lines changed

lensless/utils/dataset.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,22 @@ def natural_sort(arr):
145145
"psf": "psf_measured.png",
146146
"display_res": [900, 1200],
147147
},
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+
},
148164
}
149165

150166

lensless/utils/plot.py

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,19 @@ 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-
width = zero_crossings[-1] - zero_crossings[0]
239-
ax.set_title(f"-{plot_db_drop}dB width = {width}")
240-
ax.axvline(x=zero_crossings[0], c="k", linestyle="--")
241-
ax.axvline(x=zero_crossings[-1], c="k", linestyle="--")
238+
239+
# width = zero_crossings[-1] - zero_crossings[0]
240+
# ax.axvline(x=zero_crossings[0], c="k", linestyle="--")
241+
# ax.axvline(x=zero_crossings[-1], c="k", linestyle="--")
242+
243+
first_crossing = np.abs(zero_crossings[np.argmin(np.abs(zero_crossings))])
244+
width = 2 * np.abs(first_crossing)
245+
ax.axvline(x=-first_crossing, c="k", linestyle="--")
246+
ax.axvline(x=+first_crossing, c="k", linestyle="--")
247+
248+
ax.set_title("Cross-section")
249+
ax.set_xlabel(f"-{plot_db_drop}dB width = {width}")
250+
242251
else:
243252
warnings.warn(
244253
"Width could not be determined. Did not detect two -{} points : {}".format(
@@ -290,7 +299,7 @@ def plot_autocorr2d(vals, pad_mode="reflect", ax=None):
290299
return ax, autocorr
291300

292301

293-
def plot_autocorr_rgb(img, width=3, figsize=None):
302+
def plot_autocorr_rgb(img, width=3, figsize=None, plot_psf=False, psf_gamma=2.2):
294303
"""
295304
Plot autocorrelation of each channel of an image.
296305
@@ -306,15 +315,36 @@ def plot_autocorr_rgb(img, width=3, figsize=None):
306315
assert len(img.shape) == 3, "Image must be 3D"
307316
assert img.shape[2] == 3, "Image must have 3 color channels"
308317

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

314343
ax, _ = plot_cross_section(
315344
autocorr_c,
345+
idx=idx,
316346
color=c,
317-
ax=ax_auto[1][i],
347+
ax=ax_auto[2 if plot_psf else 1][i],
318348
plot_db_drop=width,
319349
)
320350
if i != 0:

notebook/lenslesspicam_demo.ipynb

Lines changed: 128 additions & 34 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)