-
Notifications
You must be signed in to change notification settings - Fork 0
/
wavelet.py
144 lines (110 loc) · 3.3 KB
/
wavelet.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# -*- coding: utf-8 -*-
print("Importando libs")
import pywt
import cv2
import numpy as np
import glob
'''
Wavelets
https://www.mathworks.com/help/wavelet/ref/waveletfamilies.html?requestedDomain=www.mathworks.com
===================================
Haar haar
Daubechies db
Symlets sym
Coiflets coif
BiorSplines bior
ReverseBior rbio
Meyer meyr
DMeyer dmey
Gaussian gaus
Mexican_hat mexh
Morlet morl
Complex Gaussian cgau
Shannon shan
Frequency B-Spline fbsp
Complex Morlet cmor
===================================
'''
print("Executando")
print("Lendo diretorio")
files = glob.glob("in/*.jpg")
# Read the two image
#I1 = cv2.imread('i1.bmp',0)
# First: Do wavelet transform on each image
wavelets = ["haar","db","sym","coif",
"bior","rbio","meyr","dmey","gaus","mexh",
"morl","cgau","shan","fbsp","cmor",
"db1","db2","db3","db4",
"db5","db6","db7","db8",
"db9","db10"
]
def funcaofeia(p_wavelet,p_name,I1):
wavelet = p_wavelet#wavelets[0]#'db1'
cooef1 = pywt.wavedec2(I1[:,:], wavelet)
'''
for a in range(len(cooef1)):
print(len(cooef1[a]))
print("IMAGEM")
print(I1[:,:])
print("PRIMEIRA LINHA")
print(cooef1[0][0])
print(cooef1[0][1])
print("SEGUNDA LINHA")
print(cooef1[1][0])
print(cooef1[1][1])
print(cooef1[1][2])
'''
# for line in cooef1:
# for cell in line:
# if(cell != 0):
# pass
fusedImage = pywt.waverec2(cooef1, wavelet)
'''
print("IMAGEM FUDIDA")
print(len(fusedImage))
countLine = 0
countCol = 0
countGeral = 0
print("Elementos não nulos por linha")
for line in fusedImage:
countLine = 0
for cell in line:
if(cell != 0):
countLine +=1
#print(countLine)
countGeral +=countLine
if(countLine != 0):
countCol +=1
print("COUNT GERAL=>",countGeral)
print("COUNT LINE =>",countCol)
print("ZERO LINE =>", len(fusedImage)-countCol)
'''
# MAGIA DO STACK
# Forth: normmalize values to be in uint8
fusedImage = np.multiply(np.divide(fusedImage - np.min(fusedImage),(np.max(fusedImage) - np.min(fusedImage))),255)
fusedImage = fusedImage.astype(np.uint8)
cv2.imwrite(p_name+"-XABLAU.jpg",fusedImage)
#print(len(cooef1))
cooef2 = pywt.dwt(I1[:,:], wavelet)
#cooef3 = pywt.dwt(I1[:,:], wavelet)
#print("COEF 2")
#print(cooef2[0])
#for cell in cooef2[0]:
# print(cell, end=" ")
#print(len(cooef2[1]))
cv2.imwrite(p_name+"-Digital-BIGODINHO-0.jpg",cooef2[0])
cv2.imwrite(p_name+"-Digital-BIGODINHO-1.jpg",cooef2[1])
#cv2.imwrite(p_name+"-Anal-DANONINHO-0.jpg",cooef3[0])
#cv2.imwrite(p_name+"-Anal-DANONINHO-1.jpg",cooef3[1])
for boi in files:
print("===================> RODANDO IMAGEM "+ boi)
img1 = cv2.imread(boi,0)
for suamae in wavelets:
print("================> RODANDO WAVELET "+ suamae)
try:
funcaofeia(suamae,"img\\"+boi[3:-4]+"-"+suamae,img1)
except Exception as e:
print("Mascou a "+suamae)
print(e)
#for a in range(len(cooef2)):
# print(len(cooef2[a]))