-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimg-transforms.py
More file actions
44 lines (36 loc) · 1.25 KB
/
img-transforms.py
File metadata and controls
44 lines (36 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""Tratamuennto de imágenes de tipo CATCHA"""
import matplotlib.pyplot as plt
from PIL import Image
from PIL import ImageFilter
def prepare_image(img):
"""Transform image to greyscale and blur it"""
img = img.filter(ImageFilter.SMOOTH_MORE)
img = img.filter(ImageFilter.SMOOTH_MORE)
if 'L' != img.mode:
img = img.convert('L')
return img
def remove_noise(img, pass_factor):
for column in range(img.size[0]):
for line in range(img.size[1]):
value = remove_noise_by_pixel(img, column, line, pass_factor)
img.putpixel((column, line), value)
return img
def remove_noise_by_pixel(img, column, line, pass_factor):
if img.getpixel((column, line)) < pass_factor:
return (0)
return (255)
# CATCHA tomado de
# https://prodapp2.seace.gob.pe/seacebus-uiwd-pub/buscadorPublico/buscadorPublico.xhtml?fbclid=IwAR1T1aXjVd9LD0IPTz8rhiqOREmoyF1dZOaJzbjJ2RQ5hPYDp7oB4rM4jn8
input_image = 'c2.jpeg'
img = Image.open(input_image)
# plt.imshow(img, cmap='gray')
# plt.show()
img = prepare_image(img)
# plt.imshow(img, cmap='gray')
# plt.show()
#Imagen proesado
pass_factor = 20
processed_img = remove_noise(img, pass_factor)
processed_img.save('im1.jpeg')
# plt.imshow(processed_img, cmap='gray')
# plt.show()