-
Notifications
You must be signed in to change notification settings - Fork 1
/
integrate_result.R
70 lines (61 loc) · 1.39 KB
/
integrate_result.R
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
# Integrate X images from X = 1 to 91
# For BFs, Means, and Medians
require("oro.nifti")
# To get a header, read one original file in the list (First item)
# Read filelist
data<-read.csv("list.csv")
filecount <-nrow(data)
# Get the first file
filename <- toString(data[1,1])
# Read the current nifti
Img <- readNIfTI(filename)
# Extract current image data
ImgData = oro.nifti::img_data(Img)
# Start with BFs.
for (i in 1:91){
filename <- sprintf("./Outputs/BF%d.Rdata",i)
# Read the current RData.
load (file =filename)
# Attach current BFs
for (j in 1:109){
for (k in 1:91){
ImgData[i,j,k] = BFs[j,k]
}
}
}
# Write BFs.nii
# Set Image data
oro.nifti::img_data(Img)<-ImgData
writeNIfTI(Img,"BFs",gzipped = FALSE)
# Then, Means
for (i in 1:91){
filename <- sprintf("./Outputs/Mean%d.Rdata",i)
# Read the current RData.
load (file =filename)
# Attach current Mean
for (j in 1:109){
for (k in 1:91){
ImgData[i,j,k] = Means[j,k]
}
}
}
# Write Means.nii
# Set Image data
oro.nifti::img_data(Img)<-ImgData
writeNIfTI(Img,"Means",gzipped = FALSE)
# Then, Medians
for (i in 1:91){
filename <- sprintf("./Outputs/Median%d.Rdata",i)
# Read the current RData.
load (file =filename)
# Attach current Median
for (j in 1:109){
for (k in 1:91){
ImgData[i,j,k] = Medians[j,k]
}
}
}
# Write Medians.nii
# Set Image data
oro.nifti::img_data(Img)<-ImgData
writeNIfTI(Img,"Medians",gzipped = FALSE)