Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save toshihiroryuu/96bf3dea59cb2608c455c8926e4f590b to your computer and use it in GitHub Desktop.
Save toshihiroryuu/96bf3dea59cb2608c455c8926e4f590b to your computer and use it in GitHub Desktop.
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