-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
73 lines (63 loc) · 1.56 KB
/
main.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
package main
import (
"fmt"
"os"
"log"
//https://gobyexample.com/command-line-flags
"flag"
"github.com/okieraised/gonii"
"gonum.org/v1/gonum/stat" //Correlation
)
type CorPair struct {
x []float64
y []float64
}
func debug(v ...any) {
if _, ok := os.LookupEnv("DEBUG"); ok {
log.Println(v...)
}
}
func read_nifti(input string) []float64 {
debug("reading ", input)
full_img, err := gonii.NewNiiReader(gonii.WithReadImageFile(input), gonii.WithReadRetainHeader(true))
if err != nil {
panic(err)
}
err = full_img.Parse()
if err != nil {
panic(err)
}
return full_img.GetNiiData().GetVoxels().GetDataset()
}
func main() {
roi_file := flag.String("r", "", "path to roi atlas/mask nifti image")
x_file := flag.String("x", "", "path to first input image")
y_file := flag.String("y", "", "path to second input image")
flag.Parse()
img := read_nifti(*roi_file)
img_x := read_nifti(*x_file)
img_y := read_nifti(*y_file)
debug("parsing rois")
roi_idx := make(map[float64]*CorPair)
for i, v := range img {
if v == 0 {
continue
}
x_val := img_x[i]
y_val := img_y[i]
if val, okay := roi_idx[v]; okay {
val.x = append(val.x, x_val)
val.y = append(val.y, y_val)
} else {
roi_idx[v] = &CorPair{[]float64{x_val}, []float64{y_val}}
}
}
debug("generating per roi stats")
fmt.Printf("roi\tnvox\tmean_x\tmean_y\tr\n")
for k, v := range roi_idx {
mean_x := stat.Mean(v.x, nil)
mean_y := stat.Mean(v.y, nil)
r := stat.Correlation(v.x, v.y, nil)
fmt.Printf("%.0f\t%d\t%.2f\t%.2f\t%.5f\n", k, len(v.x), mean_x, mean_y, r)
}
}