diff --git a/configs/digicam_example.yaml b/configs/digicam_example.yaml index 70af04d7..6a264f52 100644 --- a/configs/digicam_example.yaml +++ b/configs/digicam_example.yaml @@ -10,7 +10,7 @@ rpi: # mask parameters mask: fp: null # provide path, otherwise generate with seed - seed: 1 + seed: 0 shape: [54, 26] center: [57, 77] diff --git a/lensless/utils/image.py b/lensless/utils/image.py index edb213fc..4b159fd2 100644 --- a/lensless/utils/image.py +++ b/lensless/utils/image.py @@ -32,7 +32,7 @@ def resize(img, factor=None, shape=None, interpolation=cv2.INTER_CUBIC): Parameters ---------- img : :py:class:`~numpy.ndarray` - Downsampled image. + Image to downsample factor : int or float Resizing factor. shape : tuple diff --git a/scripts/measure/analyze_image.py b/scripts/measure/analyze_image.py index 7e7a3ff8..cc58d4f2 100644 --- a/scripts/measure/analyze_image.py +++ b/scripts/measure/analyze_image.py @@ -41,9 +41,9 @@ import cv2 import numpy as np import matplotlib.pyplot as plt -from lensless.utils.image import rgb2gray +from lensless.utils.image import rgb2gray, gamma_correction, resize from lensless.utils.plot import plot_image, pixel_histogram, plot_cross_section, plot_autocorr2d -from lensless.utils.io import load_image +from lensless.utils.io import load_image, load_psf, save_image @click.command() @@ -121,15 +121,26 @@ def analyze_image(fp, gamma, width, bayer, lens, lensless, bg, rg, plot_width, s fig_gray, ax_gray = plt.subplots(ncols=2, nrows=1, num="Grayscale", figsize=(15, 5)) # load PSF/image - img = load_image( - fp, - verbose=True, - bayer=bayer, - blue_gain=bg, - red_gain=rg, - nbits_out=nbits, - back=back, - ) + if lensless: + img = load_psf( + fp, + verbose=True, + bayer=bayer, + blue_gain=bg, + red_gain=rg, + nbits_out=nbits, + return_float=False, + )[0] + else: + img = load_image( + fp, + verbose=True, + bayer=bayer, + blue_gain=bg, + red_gain=rg, + nbits_out=nbits, + back=back, + ) if nbits is None: nbits = int(np.ceil(np.log2(img.max()))) @@ -194,6 +205,17 @@ def analyze_image(fp, gamma, width, bayer, lens, lensless, bg, rg, plot_width, s cv2.imwrite(save, cv2.cvtColor(img, cv2.COLOR_RGB2BGR)) print(f"\nColor-corrected RGB image saved to: {save}") + # save 8bit version for visualization + if gamma is not None: + img = img / img.max() + img = gamma_correction(img, gamma=gamma) + # -- downsample + img = resize(img, factor=1 / 4) + print(img.shape) + save_8bit = save.replace(".png", "_8bit.png") + save_image(img, save_8bit, normalize=True) + print(f"\n8bit version saved to: {save_8bit}") + plt.show() diff --git a/scripts/measure/digicam_example.py b/scripts/measure/digicam_example.py index f6e51cb6..28a84ab9 100644 --- a/scripts/measure/digicam_example.py +++ b/scripts/measure/digicam_example.py @@ -72,7 +72,7 @@ def digicam(config): ) # -- set mask - print("Setting mask") + print("Setting mask...") set_programmable_mask( pattern, "adafruit", @@ -81,7 +81,7 @@ def digicam(config): ) # -- capture - print("Capturing") + print("Capturing...") localfile, img = capture( rpi_username=rpi_username, rpi_hostname=rpi_hostname,