-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathCTnoise.py
29 lines (25 loc) · 1.06 KB
/
CTnoise.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import numpy as np
import _RandomNumberGenerator as RNG
def add(projections, Gaussian=None, Poisson=None):
if Poisson is not None:
if not np.isscalar(Poisson):
raise ValueError(
"Poisson value should be an scalar, is " + str(type(Poisson)) + " instead."
)
else:
Poisson = np.ceil(np.log2(np.max(np.abs(projections)))) # nextpow2
if Gaussian is not None:
if not isinstance(Gaussian, np.ndarray):
raise ValueError(
"Gaussian value should be an array, is " + str(type(Gaussian)) + " instead."
)
if Gaussian.shape != (2,):
raise ValueError("Gaussian shape should be 1x2, is " + str(Gaussian.shape) + "instead.")
else:
Gaussian = np.array([0, 0.5])
max_proj = np.max(projections)
projections = Poisson * np.exp(-projections / max_proj)
projections = RNG.add_noise(projections, Gaussian[0], Gaussian[1])
projections = -np.log(projections / Poisson) * max_proj
projections = np.float32(projections)
return projections