-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFullStratigraphy.py
100 lines (77 loc) · 3.24 KB
/
FullStratigraphy.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
import cv2
import numpy as np
def nothing(x):
pass
imgName = "imgs/UnoOnlyMountain.png"
img = cv2.imread(imgName)
cv2.imshow("Input", img)
#median blur
median = cv2.medianBlur(img, ksize=11)
#High Pass Filter "Sobel": to find edges
sobely = cv2.Sobel(median, -1, dx=0, dy=1, ksize=3, scale=1, delta=0, borderType=cv2.BORDER_DEFAULT)
#Erode
kernel = np.ones((3,3), np.uint8)
erode = cv2.erode(sobely,kernel, iterations = 1)
GrayErode = cv2.cvtColor(erode, cv2.COLOR_BGR2GRAY)
cv2.imshow("GrayErode", GrayErode)
#Blending images
imageblending = cv2.addWeighted(img, 0.30, erode, 0.70, 0)
cv2.imshow("Blending", imageblending)
rows, cols = GrayErode.shape
Matrix = [[0 for x in range(cols)] for y in range(rows)]
print(cols)
print(rows)
for i in range(0, rows-1,1):
for j in range(0, cols-1,1):
Matrix[i][j] = GrayErode[i,j]
sixpos = 8 #Play with this value [5,25]
threepos = sixpos -1
#Lista para anadir los puntos deseados
mapaDePuntos = []
for i in range(1, rows-1, 1):
for j in range (1, cols-1, 1):
# print(" i " +str(j*i))
#Checar primeras 6 posiciones de la matriz
if(Matrix[i-1][j - 1] < sixpos) and (Matrix[i-1][j] < sixpos) and (Matrix[i-1][j + 1]< 21) and (Matrix[i][j - 1]< sixpos) and (Matrix[i][j] < sixpos) and (Matrix[i][j + 1] <sixpos):
#Checal ultimas 3 posiciones de la matriz
if Matrix[i + 1][j - 1] > threepos or Matrix[i + 1][j] > threepos or Matrix[i + 1][j + 1] > threepos:
maxpx = 0
if Matrix[i + 1][j - 1] > maxpx:
maxpx= Matrix[i + 1][j - 1]
pos= (j-1, i+1)
if Matrix[i + 1][j] > maxpx:
maxpx = Matrix[i + 1][j]
pos = (j, i+1)
if Matrix[i + 1][j + 1] > maxpx:
maxpx = Matrix[i + 1][j + 1]
pos = (j+1, i+1)
# try:
# print(str(Matrix[i - 1][j - 1]) + " " + str(Matrix[i - 1][j]) + " " + str(Matrix[i - 1][j + 1]))
# except:
# print("Not found")
# try:
# print(str(Matrix[i][j - 1]) + " " + str(Matrix[i][j]) + " " + str(Matrix[i][j + 1]))
# except:
# print("Not found")
# try:
# print(str(Matrix[i + 1][j - 1]) + " " + str(Matrix[i + 1][j]) + " " + str(Matrix[i + 1][j + 1]))
# except:
# print("Not found")
if pos not in mapaDePuntos:
mapaDePuntos.append(pos)
else:
pass
# print("Pos in Matrix: Column->" +str(pos[0]) +" Renglon ->" +str(pos[1]) )
# print("Pos in ImLAb: column->" +str(pos[0]) +" Renglon ->" +str((165-pos[1])-1))
# print("Max Num: " + str(maxpx))
# print("---------------------------")
print(mapaDePuntos)
print(len(mapaDePuntos))
iterarPunots = len(mapaDePuntos) -1
for i in range(0, iterarPunots ,1):
img = cv2.line(img, mapaDePuntos[i], mapaDePuntos[i], (0,255,0), 1 )
#print(str(mapaDePuntos[i]) + " " + str(mapaDePuntos[i+1]))
cv2.imshow("Erode", erode)
cv2.imshow("Union", img)
cv2.waitKey()
cv2.destroyAllWindows()