Skip to content

Commit ed18f85

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 266d889 commit ed18f85

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

computer_vision/gaussian_blur.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
import math
22
import copy
3-
'''Mean thresholding algorithm for image processing
3+
4+
"""Mean thresholding algorithm for image processing
45
[More info on Wikipedia](https://en.wikipedia.org/wiki/Thresholding_(image_processing))
5-
'''
6+
"""
67
# Imagen de ejemplo: matriz 5x5
78
image = [
89
[10, 20, 30, 40, 50],
910
[20, 30, 40, 50, 60],
1011
[30, 40, 50, 60, 70],
1112
[40, 50, 60, 70, 80],
12-
[50, 60, 70, 80, 90]
13+
[50, 60, 70, 80, 90],
1314
]
1415

16+
1517
def gaussian_kernel(size, sigma=1):
1618
"""Genera un kernel gaussiano de tamaño 'size' y desviación 'sigma'"""
17-
kernel = [[0]*size for _ in range(size)]
19+
kernel = [[0] * size for _ in range(size)]
1820
center = size // 2
1921
s = 2 * sigma * sigma
2022
sum_val = 0
2123

2224
for i in range(size):
2325
for j in range(size):
2426
x, y = i - center, j - center
25-
kernel[i][j] = math.exp(-(x*x + y*y)/s)
27+
kernel[i][j] = math.exp(-(x * x + y * y) / s)
2628
sum_val += kernel[i][j]
2729

2830
# Normalizar
@@ -32,6 +34,7 @@ def gaussian_kernel(size, sigma=1):
3234

3335
return kernel
3436

37+
3538
def apply_gaussian_blur(image, kernel):
3639
"""Aplica el blur gaussiano a una imagen"""
3740
height = len(image)
@@ -52,6 +55,7 @@ def apply_gaussian_blur(image, kernel):
5255
new_image[i][j] = int(val)
5356
return new_image
5457

58+
5559
kernel = gaussian_kernel(3, sigma=1)
5660
blurred_image = apply_gaussian_blur(image, kernel)
5761

0 commit comments

Comments
 (0)