File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import math
22import 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
78image = [
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+
1517def 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+
3538def 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+
5559kernel = gaussian_kernel (3 , sigma = 1 )
5660blurred_image = apply_gaussian_blur (image , kernel )
5761
You can’t perform that action at this time.
0 commit comments