Skip to content

Commit

Permalink
Make quantization optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
ebezzam committed Aug 22, 2023
1 parent 82dfb08 commit 3079908
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions waveprop/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(
device_conv="cpu",
random_shift=False,
is_torch=False,
quantize=True,
**kwargs
):
"""
Expand All @@ -63,6 +64,8 @@ def __init__(
Whether to randomly shift the image, by default False.
is_torch : bool, optional
Whether to use pytorch, by default False.
quantize : bool, optional
Whether to quantize image, by default True.
"""
if is_torch:
self.axes = (-2, -1)
Expand All @@ -78,6 +81,7 @@ def __init__(
self.mask2sensor = mask2sensor
self.sensor = sensor_dict[sensor]
self.random_shift = random_shift
self.quantize = quantize

# for convolution
if psf is not None:
Expand Down Expand Up @@ -162,13 +166,14 @@ def propagate(self, obj, return_object_plane=False):
if self.snr_db is not None:
image_plane = add_shot_noise(image_plane, snr_db=self.snr_db)

# 5) Quantize as on sensor
image_plane = image_plane / image_plane.max()
image_plane = image_plane * self.max_val
if torch.is_tensor(image_plane):
image_plane = image_plane.to(self.output_dtype)
else:
image_plane = image_plane.astype(self.output_dtype)
# 5) (Optionaly) Quantize as on sensor
if self.quantize:
image_plane = image_plane / image_plane.max()
image_plane = image_plane * self.max_val
if torch.is_tensor(image_plane):
image_plane = image_plane.to(self.output_dtype)
else:
image_plane = image_plane.astype(self.output_dtype)

if return_object_plane:
return image_plane, object_plane
Expand Down

0 comments on commit 3079908

Please sign in to comment.