-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pyramids.go
215 lines (178 loc) · 5.53 KB
/
Pyramids.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package evm
import (
"fmt"
"gocv.io/x/gocv"
)
type Pyramid []gocv.Mat
type TimePyramidLevel struct {
SpacialPictures []gocv.Mat
SpacialPicturesGray [][]gocv.Mat
}
func CreatePyramid(img gocv.Mat, levels int) Pyramid {
Pyr := make([]gocv.Mat, (levels + 1))
gaussian_img := gocv.NewMat()
defer gaussian_img.Close()
laplacian_img := gocv.NewMat()
defer laplacian_img.Close()
//fmt.Println(img.Size())
//fmt.Println(len(*Pyr))
for j := range Pyr {
//fmt.Println("Vorgang nr: " + fmt.Sprint(j))
CalcGaussandLapl(&img, &gaussian_img, &laplacian_img)
if j == len(Pyr)-1 {
//fmt.Println("entered if")
laplacian_img = img.Clone()
} else {
//fmt.Println("entered else")
img = gaussian_img.Clone()
}
(Pyr)[j] = laplacian_img.Clone()
}
return Pyr
}
type TimePyramid struct {
//nicht vergessen typ-orientierung zu erwähnen
LevelAmount int
Frames int
RootRows int
RootCols int
Level []TimePyramidLevel
}
func CreateTimePyramid(levels int, frames int, rows int, cols int, chanum int) TimePyramid {
PyrLevels := make([]TimePyramidLevel, levels+1)
for i := range PyrLevels {
mat := make([]gocv.Mat, frames)
graymat := make([][]gocv.Mat, chanum)
for x := range graymat {
a_mat := make([]gocv.Mat, frames)
graymat[x] = a_mat
}
PyrLevels[i] = TimePyramidLevel{mat, graymat}
}
return TimePyramid{levels, frames, rows, cols, PyrLevels}
}
func (STP *TimePyramid) AddPyramid(Pyr Pyramid, PiT int) {
//PiT point int Time
for i, p := range Pyr {
STP.Level[i].SpacialPictures[PiT] = p
}
}
func (STP *TimePyramid) GetPyramid(PiT int) Pyramid {
Pyr := make([]gocv.Mat, STP.LevelAmount+1)
for i := range Pyr {
Pyr[i] = STP.Level[i].SpacialPictures[PiT]
}
return Pyr
}
func (STP *TimePyramid) CreateTimelineFromRGB(row int, col int, level int) TimeLine {
Pyr := &(STP.Level[level])
SpacePics := Pyr.SpacialPictures
resultingTimeline := InitATimeline(SpacePics[0].Channels(), len(SpacePics))
for i, pic := range SpacePics {
tmp := pic.GetVecdAt(row, col)
for j := range tmp {
resultingTimeline[j][i] = tmp[j]
}
}
return resultingTimeline
}
func (STP *TimePyramid) CreateTimelineFromGray(row int, col int, level int, chanum int) TimeLine {
Pyr := &(STP.Level[level])
GrayPics := Pyr.SpacialPicturesGray
resultingTimeline := InitATimeline(chanum, len(GrayPics[0]))
for i := range GrayPics[0] {
for j := 0; j < chanum; j++ {
resultingTimeline[j][i] = GrayPics[j][i].GetDoubleAt(row, col)
}
}
return resultingTimeline
}
type Vecb []float64
func (v Vecb) SetVecbAt(m gocv.Mat, row int, col int) {
ch := m.Channels()
for c := 0; c < ch; c++ {
m.SetDoubleAt(row, col*ch+c, v[c])
}
}
func (STP *TimePyramid) InsertTimelineAtRGB(row int, col int, level int, TL *TimeLine) {
//fmt.Printf("inserting Pixels at row: %v col%v and level %v ", row, col, level)
Pyr := &(STP.Level[level])
SpacePics := Pyr.SpacialPictures
for i := range SpacePics {
Vecb := make(Vecb, 3)
for j := range Vecb {
Vecb[j] = (*TL)[j][i]
}
Vecb.SetVecbAt(Pyr.SpacialPictures[i], row, col)
}
//fmt.Printf(": Done\n")
}
func (STP *TimePyramid) InsertTimelineAtGray(row int, col int, level int, TL *TimeLine) {
//fmt.Printf("inserting Pixels at row: %v col%v and level %v ", row, col, level)
Pyr := &(STP.Level[level])
GrayPics := Pyr.SpacialPicturesGray
for i := range GrayPics[0] {
for j := range GrayPics {
//fmt.Printf("\n(length, depth) of Timeline l: %v d: %v \n", len(*TL), len((*TL)[j]))
//fmt.Printf("\n(length, depth) of gray l: %v d: %v \n", len(Pyr.SpacialPicturesGray), len(Pyr.SpacialPicturesGray[j]))
Pyr.SpacialPicturesGray[j][i].SetDoubleAt(row, col, (*TL)[j][i])
}
}
//fmt.Printf(": Done\n")
}
func (STP *TimePyramid) Copy() TimePyramid {
return *STP
}
func (STP *TimePyramid) FilterRGBAt(row int, col int, level int, fil Filter, chanum int) {
TL := STP.CreateTimelineFromRGB(row, col, level)
FL := TL.CreateFrequencyLine(chanum)
fil.ApplyToCompl128(&FL)
TL = FL.CreateTimeline(chanum)
STP.InsertTimelineAtRGB(row, col, level, &TL)
}
func (STP *TimePyramid) FilterGrayAt(row int, col int, level int, fil Filter, chanum int) {
TL := STP.CreateTimelineFromGray(row, col, level, chanum)
FL := TL.CreateFrequencyLine(chanum)
if level > fil.LevelMin {
fil.ApplyToCompl128(&FL)
}
TL = FL.CreateTimeline(chanum)
STP.InsertTimelineAtGray(row, col, level, &TL)
}
func (STP *TimePyramid) RGB2Gray() {
for i := range STP.Level {
LEVEL := &STP.Level[i]
for j := range LEVEL.SpacialPictures {
BGR := gocv.Split(LEVEL.SpacialPictures[j])
for k := range BGR {
LEVEL.SpacialPicturesGray[k][j] = BGR[k]
}
}
}
}
func (STP *TimePyramid) Gray2RGB() {
for i := range STP.Level {
LEVEL := &STP.Level[i]
for j := range LEVEL.SpacialPictures {
BGR := make([]gocv.Mat, 3)
for k := range BGR {
BGR[k] = LEVEL.SpacialPicturesGray[k][j]
//gocv.CvtColor(BGR[k], &(BGR[k]), gocv.ColorBGRToGray)
}
//xor := BGR[0].Clone()
//gocv.BitwiseXor(BGR[0], BGR[1], &xor)
//if gocv.CountNonZero(xor) == 0 {
// panic("error")
//}
//fmt.Printf("Tested if we are about to merge the same pictures at level %v and frame %v\n", i, j)
gocv.Merge(BGR, &LEVEL.SpacialPictures[j])
//fmt.Printf("Merged BGR with len : %v into image with %v channels \n", len(BGR), LEVEL.SpacialPictures[j].Channels())
}
}
}
func (STP *TimePyramid) PrintShape() {
fmt.Printf("Printing shape of Pyramids:\n")
for i := range STP.Level {
fmt.Printf("At Levle %v the RGBshape is %v and the Gray shape is %v\n", i, STP.Level[i].SpacialPictures[0].Size(), STP.Level[i].SpacialPicturesGray[0][0].Size())
}
}