Skip to content

Commit

Permalink
Add random seed parameter to Camera.grab (#139)
Browse files Browse the repository at this point in the history
* Add random seed parameter to Camera
  • Loading branch information
aturcotte authored Jan 19, 2022
1 parent 8e72ba1 commit 575e536
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions emva1288/camera/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def __init__(self,
u_esat=15000.,

dsnu=None,
prnu=None
prnu=None,
seed=None
):
"""Camera simulator init method.
Expand Down Expand Up @@ -107,6 +108,8 @@ def __init__(self,
prnu : np.array, optional
PRNU image in percentages (1 = 100%), array with the same shape
of the image. Every image is multiplied by it.
seed : int, optional
A seed to initialize the random number generator.
"""
self._pixel_area = pixel_area
self._bit_depth = bit_depth
Expand Down Expand Up @@ -162,6 +165,8 @@ def __init__(self,
self.environment = {'temperature': temperature,
'f_number': f_number}

self._rng = np.random.default_rng(seed)

@property
def bit_depth(self):
"""The number of bits allowed for a gray value for one pixel."""
Expand Down Expand Up @@ -297,17 +302,17 @@ def grab(self, radiance, temperature=None, f_number=None):
# Thermally induced electrons image
u_d = self._u_therm(temperature=temperature)
# Noise centred on the number of electrons thermally generated
img_e = np.random.poisson(u_d, size=self._shape)
img_e = self._rng.poisson(u_d, size=self._shape)

###############################
# Light induced electrons image
u_e = self._u_e(radiance, f_number=f_number)
# Noise centred on the number of electrons from the Light
img_e += np.random.poisson(u_e, size=self._shape)
img_e += self._rng.poisson(u_e, size=self._shape)
####################################################################
# Electronics induced electrons image and Dark Signal non uniformity
variance = np.sqrt(self._sigma2_dark_0)
dark_signal = self._dsnu + np.random.normal(loc=self._dark_signal_0,
dark_signal = self._dsnu + self._rng.normal(loc=self._dark_signal_0,
scale=variance,
size=self._shape)
img_e = img_e + dark_signal
Expand All @@ -320,7 +325,7 @@ def grab(self, radiance, temperature=None, f_number=None):
img = self.K * img_e

# Quantization noise image
img_q = np.random.uniform(-0.5, 0.5, self._shape)
img_q = self._rng.uniform(-0.5, 0.5, self._shape)
img += img_q

# Offset on the dark_signal
Expand Down

0 comments on commit 575e536

Please sign in to comment.