nifreeze.testing.phantoms module¶
Noise of the synthetic reference datasets (see Synthetic reference data).
The simulator writes noise-free images. Noise is added afterwards, so that one noise-free volume can be stored once and given the same noise in every dataset that contains it, perturbed or not: the noise of a volume is drawn from a generator keyed on a seed and on the volume’s index in the full dataset.
- nifreeze.testing.phantoms.add_noise(volumes: ndarray, sigma: float, seed: int, indices: Iterable[int] | None = None) ndarray[source]¶
Add complex Gaussian noise to noise-free volumes, and take the magnitude.
The noise-free volumes are real (their phase is zero). Each channel gets noise of standard deviation
sigma, so the magnitude follows a Rice distribution, and a Rayleigh one where there is no signal.- Parameters:
volumes (
ndarray) – Noise-free volumes, of shape(N, X, Y, Z).sigma (
float) – Standard deviation of the real and of the imaginary noise.seed (
int) – Seed of the noise realization.indices (
Iterable, optional) – Index of each volume in the full dataset (0, 1, ...by default), which keys the noise of that volume.
- Returns:
The noisy magnitudes,
float32, of the same shape.- Return type:
Examples
>>> volumes = np.zeros((3, 4, 4, 4)) >>> noisy = add_noise(volumes, 1.0, seed=7) >>> np.array_equal(add_noise(volumes[1:], 1.0, seed=7, indices=[1, 2]), noisy[1:]) True
- nifreeze.testing.phantoms.noise_sigma(bzero: ndarray, white_matter: ndarray, snr: float) float[source]¶
Standard deviation of the noise in each channel for a given b=0 SNR.
- Parameters:
- Returns:
The standard deviation of the real and of the imaginary noise.
- Return type:
Examples
>>> noise_sigma(np.full((2, 2, 2), 30.0), np.ones((2, 2, 2), dtype=bool), 10.0) 3.0