-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhenotype.go
56 lines (49 loc) · 1.33 KB
/
Phenotype.go
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
package main
type Phenotype struct {
segments [][]Vertex
segmentIdMap map[Vertex]int
picture *Picture
}
func initPhenotype(segments [][]Vertex, pic *Picture) Phenotype {
return Phenotype{segments, generateSegmentIdMap(segments), pic}
}
func generateSegmentIdMap(segments [][]Vertex) map[Vertex]int {
segmentIdMap := make(map[Vertex]int)
for s := range segments {
for v := range segments[s] {
segmentIdMap[segments[s][v]] = s
}
}
return segmentIdMap
}
func (p Phenotype) OverallDeviation() float64 {
deviation := 0.0
for _, segment := range p.segments {
centeroid := averageSegmentColor(segment, p.picture)
p2 := rgbaToPixel(centeroid)
for _, node := range segment {
p1 := p.picture.pixels[node.X][node.Y]
deviation += euclideanDistance(&p1, &p2)
}
}
return deviation
}
func (p Phenotype) EdgeValue() float64 {
edgeValue := 0.0
for s := range p.segments {
for _, vertex := range p.segments[s] {
node := Vertex{vertex.X, vertex.Y}
p1 := p.picture.pixels[node.X][node.Y]
neighbours := getAllCardinalNeighbours(node)
for _, neighbour := range neighbours {
if inBounds(neighbour) {
if p.segmentIdMap[vertex] != p.segmentIdMap[neighbour] {
p2 := p.picture.pixels[neighbour.X][neighbour.Y]
edgeValue += euclideanDistance(&p1, &p2)
}
}
}
}
}
return edgeValue
}