-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_label.go
74 lines (56 loc) · 1.93 KB
/
example_label.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
// Demo application for the neurogo package. Reads a FreeSurfer surface label file containing all vertices of the cortex. Used to mask out medial wall.
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"os"
"github.com/dfsp-spirit/neuro"
)
var (
labelfile string
exportfile_json string
verbosity * int
err error
)
func init() {
flag.StringVar(&labelfile, "labelfile", "lh.cortex.label", "The input label file to read, in ASCII FreeSurfer label format.")
flag.StringVar(&exportfile_json, "exportjson", "", "Output file to which to export label data in JSON format. Path to it must exist.")
verbosity = flag.Int("verbosity", 2, "Verbosity level: 0 = silent, 1 = info, 2 = debug.")
}
func main() {
apptag := "[EX4] "
//neurogo.Verbosity = *verbosity
flag.Parse()
fmt.Println("=====[ Neuro Example 4: Read a FreeSurfer label file ]=====")
if *verbosity > 0 {
fmt.Println(apptag, "labelfile:", labelfile)
fmt.Println(apptag, "verbosity:", *verbosity)
}
if _, err := os.Stat(labelfile); err != nil {
fmt.Printf("%sCould not stat file '%s': '%s', exiting.\n.", apptag, labelfile, err)
return
}
label, err := neuro.ReadFsLabel(labelfile)
if err != nil {
fmt.Printf("%sFailed to read label data from file '%s': '%s'.\n", apptag, labelfile, err)
return
}
if *verbosity > 0 {
fmt.Printf("%sRead label containing %d vertices from file '%s'.\n", apptag, len(label.Value), labelfile)
}
if len(exportfile_json) > 0 {
fmt.Printf("%sExporting label data in format %s to file '%s'.\n", apptag, "JSON", exportfile_json)
file, err := json.MarshalIndent(label, "", " ")
if err != nil {
fmt.Printf("%sError converting label data to JSON: %s", apptag, err)
}
err = ioutil.WriteFile(exportfile_json, file, 0644)
if err != nil {
fmt.Printf("%sError exporting label data: %s", apptag, err)
} else {
fmt.Printf("%sExported label data to file '%s'.\n", apptag, exportfile_json)
}
}
}