forked from yu4u/noise2noise
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request yu4u#1 from yu4u/feature/select_noise_models
Feature/select noise models
- Loading branch information
Showing
3 changed files
with
38 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import numpy as np | ||
|
||
|
||
def get_noise_model(noise_type="gaussian,0,50"): | ||
tokens = noise_type.split(sep=",") | ||
|
||
if tokens[0] == "gaussian": | ||
min_stddev = int(tokens[1]) | ||
max_stddev = int(tokens[2]) | ||
|
||
def gaussian_noise(img): | ||
noise_img = img.astype(np.float) | ||
stddev = np.random.uniform(min_stddev, max_stddev) | ||
noise = np.random.randn(*img.shape) * stddev | ||
noise_img += noise | ||
noise_img = np.clip(noise_img, 0, 255).astype(np.uint8) | ||
return noise_img | ||
return gaussian_noise | ||
elif tokens[0] == "clean": | ||
return lambda img: img |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters