@param n : float, noise fraction (0, inf) @param sigma : float, smoothing of noise component @return[out] im : array like im with +-n *100%im noise added
(im, n, warn_zero=True, sigma=1)
| 433 | |
| 434 | |
| 435 | def noise(im, n, warn_zero=True, sigma=1): |
| 436 | """ |
| 437 | @param n : float, noise fraction (0, inf) |
| 438 | @param sigma : float, smoothing of noise component |
| 439 | @return[out] im : array like im with +-n *100%im noise added |
| 440 | """ |
| 441 | if n < 0: |
| 442 | raise ValueError("Noise must be positive") |
| 443 | elif n == 0: |
| 444 | if warn_zero: |
| 445 | log.warn("zero noise") |
| 446 | return im |
| 447 | r = gaussian_filter(np.random.random(im.shape), sigma=sigma, mode='constant') |
| 448 | return im * (1 + n * (2 * r - 1)) |
| 449 | |
| 450 | |
| 451 | def toPetMmr(im, pad=True, dtype=np.float32, outres="mMR", modes=None, |