Skip to content

Commit

Permalink
fixed bug in noise calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dingel321 committed Jan 26, 2024
1 parent 2c07580 commit 07db6f3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/cryo_sbi/wpa_simulator/noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def get_snr(images, snr):
images[:, mask], dim=[-1]
) # images are not centered at 0, so std is not the same as power
assert signal_power.shape[0] == images.shape[0]
noise_power = signal_power / torch.sqrt(torch.pow(snr, torch.tensor(10)))

noise_power = signal_power.reshape(-1, 1, 1) / torch.sqrt(torch.pow(torch.tensor(10), snr))
print(torch.pow(snr, torch.tensor(10)))
return noise_power


Expand All @@ -56,10 +56,11 @@ def add_noise(image: torch.Tensor, snr, seed=None) -> torch.Tensor:
"""

if seed is not None:
torch.manual_seed(seed) #
torch.manual_seed(seed)

noise_power = get_snr(image, snr)
noise = torch.randn_like(image, device=image.device)
print(noise.shape, noise_power.shape, image.shape, snr.shape)
noise = noise * noise_power.reshape(-1, 1, 1)

image_noise = image + noise
Expand Down

0 comments on commit 07db6f3

Please sign in to comment.