Skip to content

Commit

Permalink
Fix top_left naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
ebezzam committed May 14, 2024
1 parent 7ceaeda commit 62b86f6
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 26 deletions.
2 changes: 1 addition & 1 deletion configs/benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ huggingface:
image_res: [900, 1200] # used during measurement
rotate: True # if measurement is upside-down
alignment:
topright: [80, 100] # height, width
top_left: [80, 100] # height, width
height: 200
downsample: 1

Expand Down
4 changes: 2 additions & 2 deletions configs/train_digicam_multimask.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ files:
display_res: [900, 1200] # used during measurement
rotate: True # if measurement is upside-down
alignment:
topright: [80, 100] # height, width
top_left: [80, 100] # height, width
height: 200

# TODO: these parameters should be in the dataset?
alignment:
# when there is no downsampling
topright: [80, 100] # height, width
top_left: [80, 100] # height, width
height: 200

training:
Expand Down
4 changes: 2 additions & 2 deletions configs/train_digicam_singlemask.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ files:
display_res: [900, 1200] # used during measurement
rotate: True # if measurement is upside-down
alignment:
topright: [80, 100] # height, width
top_left: [80, 100] # height, width
height: 200

# TODO: these parameters should be in the dataset?
alignment:
# when there is no downsampling
topright: [80, 100] # height, width
top_left: [80, 100] # height, width
height: 200

training:
Expand Down
2 changes: 1 addition & 1 deletion configs/train_unrolledADMM.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ files:
extra_eval: null # dict of extra datasets to evaluate on

alignment: null
# topright: null # height, width
# top_left: null # height, width
# height: null

torch: True
Expand Down
6 changes: 3 additions & 3 deletions lensless/hardware/slm.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ def adafruit_sub2full(

# pad to full pattern
pattern = np.zeros((3, 128, 160), dtype=np.uint8)
topleft = [center[0] - controllable_shape[1] // 2, center[1] - controllable_shape[2] // 2]
top_left = [center[0] - controllable_shape[1] // 2, center[1] - controllable_shape[2] // 2]
pattern[
:,
topleft[0] : topleft[0] + controllable_shape[1],
topleft[1] : topleft[1] + controllable_shape[2],
top_left[0] : top_left[0] + controllable_shape[1],
top_left[1] : top_left[1] + controllable_shape[2],
] = subpattern_rgb.astype(np.uint8)
return pattern

Expand Down
16 changes: 8 additions & 8 deletions lensless/utils/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ def __init__(
If `psf` not provided, the SLM to use for the PSF simulation, by default "adafruit".
alignment : dict, optional
Alignment parameters between lensless and lensed data.
If "topright", "height", and "width" are provided, the region-of-interest from the reconstruction of ``lensless`` is extracted and ``lensed`` is reshaped to match.
If "top_left", "height", and "width" are provided, the region-of-interest from the reconstruction of ``lensless`` is extracted and ``lensed`` is reshaped to match.
If "crop" is provided, the region-of-interest is extracted from the simulated lensed image, namely a ``simulation`` configuration should be provided within ``alignment``.
return_mask_label : bool, optional
If multimask dataset, return the mask label (True) or the corresponding PSF (False).
Expand Down Expand Up @@ -1106,11 +1106,11 @@ def __init__(
self.crop = None
if alignment is not None:
# preparing ground-truth in expected shape
if "topright" in alignment:
if "top_left" in alignment:
self.alignment = dict(alignment.copy())
self.alignment["topright"] = (
int(self.alignment["topright"][0] / downsample),
int(self.alignment["topright"][1] / downsample),
self.alignment["top_left"] = (
int(self.alignment["top_left"][0] / downsample),
int(self.alignment["top_left"][1] / downsample),
)
self.alignment["height"] = int(self.alignment["height"] / downsample)

Expand Down Expand Up @@ -1304,14 +1304,14 @@ def extract_roi(self, reconstruction, lensed=None, axis=(1, 2)):
assert max(axis) < n_dim, "Axis should be within the dimensions of the reconstruction."

if self.alignment is not None:
top_right = self.alignment["topright"]
top_left = self.alignment["top_left"]
height = self.alignment["height"]
width = self.alignment["width"]

# extract according to axis
index = [slice(None)] * n_dim
index[axis[0]] = slice(top_right[0], top_right[0] + height)
index[axis[1]] = slice(top_right[1], top_right[1] + width)
index[axis[0]] = slice(top_left[0], top_left[0] + height)
index[axis[1]] = slice(top_left[1], top_left[1] + width)
reconstruction = reconstruction[tuple(index)]

# rotate if necessary
Expand Down
4 changes: 2 additions & 2 deletions scripts/recon/digicam_mirflickr.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ def apply_pretrained(config):
if save:
print(f"Saving images to {os.getcwd()}")
alignment = test_set.alignment
top_right = alignment["topright"]
top_left = alignment["top_left"]
height = alignment["height"]
width = alignment["width"]
res_np = img[top_right[0] : top_right[0] + height, top_right[1] : top_right[1] + width]
res_np = img[top_left[0] : top_left[0] + height, top_left[1] : top_left[1] + width]
lensed_np = lensed[0].cpu().numpy()
save_image(lensed_np, f"original_idx{idx}.png")
save_image(res_np, f"{model_name}_idx{idx}.png")
Expand Down
8 changes: 1 addition & 7 deletions scripts/recon/train_learning_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,7 @@ def train_learned(config):
res_np, lensed_np = test_set.extract_roi(
res_np, lensed=lensed_np, axis=(0, 1)
)
# if alignment is not None:
# top_right = alignment["topright"]
# height = alignment["height"]
# width = alignment["width"]
# res_np = res_np[
# top_right[0] : top_right[0] + height, top_right[1] : top_right[1] + width
# ]

cropped = True

elif config.training.crop_preloss:
Expand Down

0 comments on commit 62b86f6

Please sign in to comment.