Skip to content

Instantly share code, notes, and snippets.

@lefuturiste
Created April 1, 2021 13:20
Show Gist options
  • Save lefuturiste/dc950691165639457e605e1974382441 to your computer and use it in GitHub Desktop.
Save lefuturiste/dc950691165639457e605e1974382441 to your computer and use it in GitHub Desktop.
Blur with average, terrible complexity
import numpy as np
from PIL import Image
J = np.asarray(Image.open('36.jpg').convert('RGB'))
r = 20
def inShape(y, x, shape):
return x >= 0 and y >= 0 and x < shape[1] and y < shape[0]
def blur_cu(IM):
height, width, _ = IM.shape
OUT = np.zeros(IM.shape, np.uint8)
for i in range(height):
for j in range(width):
color = np.array([0, 0, 0])
count = 0
for t in range(i-r, i+r, 1):
for k in range(j-r, j+r, 1):
#(t, k) les coordonées
if inShape(t, k, IM.shape):
count += 1
color += IM[t][k]
OUT[i,j] = color/count
#OUT[i,j] = color/(4*r**2)
return OUT
out = Image.fromarray(blur_cu(J), 'RGB')
out.save('out.jpg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment