Skip to content

Commit

Permalink
Improve analyze image script.
Browse files Browse the repository at this point in the history
  • Loading branch information
ebezzam committed May 27, 2024
1 parent 9026651 commit 3ebfeff
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion configs/digicam_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion lensless/utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 33 additions & 11 deletions scripts/measure/analyze_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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())))

Expand Down Expand Up @@ -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()


Expand Down
4 changes: 2 additions & 2 deletions scripts/measure/digicam_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def digicam(config):
)

# -- set mask
print("Setting mask")
print("Setting mask...")
set_programmable_mask(
pattern,
"adafruit",
Expand All @@ -81,7 +81,7 @@ def digicam(config):
)

# -- capture
print("Capturing")
print("Capturing...")
localfile, img = capture(
rpi_username=rpi_username,
rpi_hostname=rpi_hostname,
Expand Down

0 comments on commit 3ebfeff

Please sign in to comment.