forked from alejandroklever/detedge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
86 lines (77 loc) · 4.79 KB
/
main.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import io
import numpy as np
import streamlit as st
from PIL import Image
from detedge import lpf, hpf, bpf, detect_edges
from detedgewev import detect_edges_wavelet as detect_edges_wav
if __name__ == '__main__':
option = st.sidebar.selectbox('Options', options=['-', 'Fourier', 'Wavelet'], index=0)
if option == '-':
st.markdown("""
# Proyecto de Matematica Numerica
## Tema:
Deteccion de borde y eliminacion de ruidos en imagenes usando FFT y Wavelets
### Autores:
Alejandro Klever Clemente
Miguel Angel Gonzalez Calles
Laura Tamayo Blanco
""")
elif option == 'Fourier':
file: io.BytesIO = st.sidebar.file_uploader('Upload Photo', type=["jpg", "jpeg", "png"])
if file is not None:
img: np.ndarray = np.array(Image.open(file).convert('L'))
st.image(image=img, caption='Input Image', use_column_width=True)
option = st.sidebar.selectbox('Select Mask',
options=[
'low pass filter',
'high pass filter',
'band pass filter'],
index=0
)
if 'low pass filter' == option:
lpf_radio = st.sidebar.slider('low frequency radio', max_value=100., value=9., step=.01)
img_back, (spectrum, mask) = detect_edges(img, lpf, lpf_radio * min(img.shape) / 100)
elif 'high pass filter' == option:
hpf_radio = st.sidebar.slider('high frequency radio', max_value=100., value=9., step=.01)
img_back, (spectrum, mask) = detect_edges(img, hpf, hpf_radio * min(img.shape) / 100)
else:
rin, rout = st.sidebar.slider('band frequency radio', max_value=100., value=(5., 12.), step=.01)
img_back, (spectrum, mask) = detect_edges(img, bpf,
(rin * min(img.shape) / 100, rout * min(img.shape) / 100)
)
st.sidebar.image(image=np.uint8(spectrum), caption='After FFT', use_column_width=True)
st.sidebar.image(image=np.uint8(mask), caption='FFT + MASK', use_column_width=True)
st.image(image=np.uint8(img_back), caption='After FFT Inverse', use_column_width=True)
else:
file: io.BytesIO = st.sidebar.file_uploader('Upload Photo', type=["jpg", "jpeg", "png"])
if file is not None:
img: np.ndarray = np.array(Image.open(file).convert('L'))
st.image(image=img, caption='Input Image', use_column_width=True)
option = st.sidebar.selectbox('Select Mask',
options=[
'low pass filter',
'high pass filter',
'band pass filter'],
index=0
)
wavelet = st.sidebar.selectbox('Select Wavelet',
options=[
'db6',
'haar'],
index=0
)
if 'low pass filter' == option:
lpf_radio = st.sidebar.slider('low frequency radio', max_value=100., value=40., step=.01)
img_back, (spectrum, mask) = detect_edges_wav(img, lpf, lpf_radio * min(img.shape) / 100)
elif 'high pass filter' == option:
hpf_radio = st.sidebar.slider('high frequency radio', max_value=100., value=30., step=.01)
img_back, (spectrum, mask) = detect_edges_wav(img, hpf, hpf_radio * min(img.shape) / 100,
wavelet=wavelet)
else:
rin, rout = st.sidebar.slider('band frequency radio', max_value=100., value=(10., 20.), step=.01)
img_back, (spectrum, mask) = detect_edges_wav(img, bpf,
(rin * min(img.shape) / 100, rout * min(img.shape) / 100),
wavelet=wavelet)
st.sidebar.image(image=np.uint8(spectrum), caption='After Analysis ', use_column_width=True)
st.sidebar.image(image=np.uint8(mask), caption='Coefficients + MASK', use_column_width=True)
st.image(image=np.uint8(img_back), caption='After Synthesis', use_column_width=True)