Skip to content

Instantly share code, notes, and snippets.

@ryul99
Last active April 23, 2020 05:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryul99/7dfa5c0345fde286e8c359e90c861044 to your computer and use it in GitHub Desktop.
Save ryul99/7dfa5c0345fde286e8c359e90c861044 to your computer and use it in GitHub Desktop.
testing gaussian noise
# made by @mori_inj
import numpy as np
import matplotlib.pyplot as plt
import cv2
p = 2#np.inf
pert = 100#1000
im = cv2.imread('00000000.png')
#print(type(im)) # 처음부터 numpy
#print(im.shape) # (H, W, C)
print(im.size) # H x W x C
noise = np.random.normal(0, 1, np.size(im))
noise = noise / np.linalg.norm(noise, p) * pert
print(np.linalg.norm(noise, p), pert)
im += noise.reshape(im.shape).astype(np.uint8)
print(np.amax(im), np.amin(im), type(im[0, 0, 0])) # np.uint8 (0 ~ 255)
plt.imshow(im[:,:,::-1], interpolation='bicubic') # R G B
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment