Created
April 1, 2021 13:20
-
-
Save lefuturiste/dc950691165639457e605e1974382441 to your computer and use it in GitHub Desktop.
Blur with average, terrible complexity
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
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