Skip to content

Commit

Permalink
Clean up script and backward compatability.
Browse files Browse the repository at this point in the history
  • Loading branch information
ebezzam committed Sep 6, 2024
1 parent 7937bce commit 3d53857
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lensless/utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def get_max_val(img, nbits=None):
max_val : int
Maximum pixel value.
"""
# assert img.dtype not in FLOAT_DTYPES
assert img.dtype not in FLOAT_DTYPES
if nbits is None:
nbits = int(np.ceil(np.log2(img.max())))

Expand Down
9 changes: 3 additions & 6 deletions lensless/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from lensless.utils.image import bayer2rgb_cc, print_image_info, resize, rgb2gray, get_max_val
from lensless.utils.plot import plot_image


def load_mask(fp):
mask = np.load(fp)
return np.expand_dims(mask, axis=0)
Expand Down Expand Up @@ -127,7 +128,7 @@ def load_image(
img = np.load(fp)
elif "mat" in fp:
mat = scipy.io.loadmat(fp)
img = mat['psf'][:,:,0]
img = mat["psf"][:, :, 0]
else:
img = cv2.imread(fp, cv2.IMREAD_UNCHANGED)

Expand Down Expand Up @@ -209,10 +210,6 @@ def load_image(
else:
if dtype is None:
dtype = original_dtype
img = img.astype(np.float64)

img = img[10:260, 35:320-35]
img = img / np.linalg.norm(img)

return img

Expand Down Expand Up @@ -390,7 +387,7 @@ def load_psf(
if return_bg:
return psf, bg
else:
return psf.astype(np.float64)
return psf


def load_data(
Expand Down
23 changes: 14 additions & 9 deletions scripts/recon/hyperspectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,35 @@
import time
import pathlib as plib
import matplotlib.pyplot as plt
from lensless.utils.io import load_data
from lensless.utils.io import load_image
from lensless import (
HyperSpectralFISTA,
)
import scipy


@hydra.main(version_base=None, config_path="../../configs", config_name="defaults_recon")
def gradient_descent(
config,
):

# load mask and PSF
# set paths
mask_fp = "/root/FORKS/LenslessPiCamNoa/data/mask.npy"
psf_fp = "/root/FORKS/LenslessPiCamNoa/data/psf.mat"
data_fp = "/root/FORKS/LenslessPiCamNoa/data/266_lensless.png"

### - put your paths
# mask_fp = None
# psf_fp = None
# data_fp = None

# load mask and PSF
mask = np.load(mask_fp)
mask = np.expand_dims(mask, axis=0)
mask = mask.astype(np.float32)

# load PSF
import scipy

psf_fp = "/root/FORKS/LenslessPiCamNoa/data/psf.mat"
mat = scipy.io.loadmat(psf_fp)
psf = mat["psf"][:, :, 0]
psf = psf.astype(np.float32)
Expand All @@ -44,9 +52,6 @@ def gradient_descent(
psf = np.expand_dims(psf, axis=-1) # add channels

# load data
from lensless.utils.io import load_image

data_fp = "/root/FORKS/LenslessPiCamNoa/data/266_lensless.png"
data = load_image(
data_fp,
return_float=True,
Expand Down Expand Up @@ -74,8 +79,8 @@ def gradient_descent(

start_time = time.time()
res = recon.apply(
n_iter=500,
disp_iter=50,
n_iter=100,
disp_iter=20,
save=save,
gamma=1.0,
plot=False,
Expand Down

0 comments on commit 3d53857

Please sign in to comment.