Created
April 10, 2019 12:05
-
-
Save toshihiroryuu/96bf3dea59cb2608c455c8926e4f590b to your computer and use it in GitHub Desktop.
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
from PIL import Image | |
import matplotlib.pyplot as plt | |
import numpy as np | |
def gauss_noise(img): | |
row,col,ch= img.height, img.width,3 | |
loc = 0 | |
scale=30 | |
red, green, blue = img.split() | |
for y in range(img.height): | |
for x in range(img.width): | |
gauss = np.random.normal(loc,scale) | |
# print(x) | |
# print(gauss) | |
value = img.getpixel((x, y)) | |
# image_red = value + gauss | |
image_red = (value[0] + int(gauss), value[1], value[2]) | |
print(int(gauss)) | |
img.putpixel((x, y), image_red) | |
return img | |
file_path = "/home/cat.jpg" | |
img = Image.open(file_path) | |
out=gauss_noise(img) | |
out.save('gauss.png') | |
plt.imshow(out) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment