Repository navigation
Expand file tree
/
Copy pathprocess.py
More file actions
65 lines (56 loc) · 1.45 KB
/
Copy pathprocess.py
File metadata and controls
65 lines (56 loc) · 1.45 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
"""
Mardigon Toler
Gregory Hughes
"""
import morpho
import matplotlib.pyplot as plt
#import skimage.util as util
import skimage.color as color
import skimage.feature as feature
import skimage.io as io
import numpy as np
# Make this the path to the file you wish to process
fname = "test1a.png"
"""
Our first script for finding eyes using template matching"
"""
img = io.imread(fname)
imgB = color.rgb2grey(img) > 0.333
io.imshow(imgB)
plt.show()
se1 = [[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]]
se1 = np.asarray(se1)
imgE = morpho.morphoErode(imgB, se1, 0)
io.imshow(imgE)
plt.show()
imgD = morpho.morphoDilate(imgB, se1, 0)
io.imshow(imgD)
plt.show()
# find hit-or-miss transform
imgH = imgE ^ imgD
io.imshow(imgH)
plt.show()
#closing
imgC = morpho.morphoErode(morpho.morphoDilate(imgH, se1, 0), se1, 0)
io.imshow(imgC)
plt.show()
# region of interest
roi = morpho.findROI(imgC)
imgroi = imgH[roi[2]:len(imgH),roi[0]:roi[1]]
io.imshow(imgroi)
plt.show()
se2 = np.ones(len(imgroi[0])) >=1
unit = round(len(imgroi)/75)
mid = len(se2)//2
se2[mid-(unit*5):mid+(unit*5)] = 0
se2[0:(unit*3)] = 0
se2[len(se2)-(unit*3):len(se2)] = 0
se2 = np.reshape(se2,(1,len(se2)))
# match SE for row with eyes
imgT = feature.match_template(imgroi, se2, True)
io.imshow(imgT)
plt.show()
imgF = feature.match_template(imgroi, se2, False)
io.imshow(np.repeat(imgF,100,axis=1))
plt.show()