forked from emiltan97/pmvs-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.py
63 lines (52 loc) · 1.63 KB
/
filter.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
from optim import computeGStar
import utils
from initialmatch import computeVp
def run(patches, images, sigma, gamma) :
for patch in patches :
if filter1(patch, images) or filter2(patch, sigma, gamma) or filter3(patch, images) :
patches.remove(patch)
return patches
def filter1(patch, images) :
U = []
for cell in patch.cells :
image = utils.getImage(cell[0], images)
i_cell = image.cells[cell[1][1]][cell[1][0]]
for p in i_cell.q :
if utils.isNeighbour(patch, p, 2) :
continue
U.append(p)
a = len(patch.VpStar)
b = 1 - utils.computeGStar(patch)
c = 0
for pi in U :
c += 1 - computeGStar(pi)
if a * b < c :
return True
return False
def filter2(patch, sigma, gamma) :
images = computeVp(patch.VpStar, patch, patch.ref, sigma)
if len(images) < gamma :
return True
return False
def filter3(patch, images) :
patches = []
for cell in patch.cells :
image = utils.getImage(cell[0], images)
C = [
image.cells[cell[1][1]][cell[1][0]],
image.cells[cell[1][1] + 1][cell[1][0]],
image.cells[cell[1][1] - 1][cell[1][0]],
image.cells[cell[1][1]][cell[1][0] + 1],
image.cells[cell[1][1]][cell[1][0] - 1]
]
for c in C :
for p in c.q :
patches.append(p)
pos = 0
for p in patches :
if utils.isNeighbour(patch, p, 2) :
pos += 1
ratio = pos / len(patches) * 100
if ratio < 0.25 :
return True
return False