parent
edb706659f
commit
04ac5cca7a
After Width: | Height: | Size: 201 KiB |
@ -0,0 +1,31 @@
|
||||
from nnnar import *
|
||||
from knn import *
|
||||
import random
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
image = plt.imread('./data/img.jpg')
|
||||
image = np.array(image)
|
||||
|
||||
|
||||
height, width, _ = image.shape
|
||||
|
||||
def replaceRandomPixel(image,nb):
|
||||
for i in range(nb):
|
||||
y = random.randint(0, height - 1)
|
||||
x = random.randint(0, width - 1)
|
||||
v = [random.randint(0,255), random.randint(0,255), random.randint(0,255)]
|
||||
n = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]
|
||||
for i in n:
|
||||
if (y+i[0] >= 0 and y+i[0] < height and x+i[1] >= 0 and x+i[1] < width):
|
||||
image[y+i[0],x+i[1]] = v
|
||||
return image
|
||||
|
||||
|
||||
image = replaceRandomPixel(image, 1000)
|
||||
|
||||
|
||||
plt.imshow(image)
|
||||
plt.axis('off')
|
||||
plt.show()
|
Loading…
Reference in new issue