-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path000Average.bms
More file actions
99 lines (92 loc) · 3.61 KB
/
000Average.bms
File metadata and controls
99 lines (92 loc) · 3.61 KB
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
GetParamCount( Average_count ${Average_INPUT_FILES} )
GetParamCount( HM_count ${HISTOGRAM_MATCH} )
If( ${HM_count} != ${Average_count} )
echo( 'Average_INPUT_SUFFIX and HISTOGRAM_MATCH must have the same number of parameters' )
exit()
EndIf( ${HM_count} != ${Average_count} )
MakeDirectory( ${tempDir} )
GetParam( first_case ${CASES} 0 )
MakeDirectory( ${outputDir} )
###Save script config
If( ${ScriptName} != '' )
GetFilename( name ${ScriptName} NAME )
CopyFile( ${ScriptName} ${outputDir}/${name} )
EndIf( ${ScriptName} != '' )
set( posAv 0 )
ForEach( j ${Average_INPUT_FILES} )
GetFilename( Average_TAG ${j} NAME_WITHOUT_EXTENSION )
GetParam( Current_HM ${HISTOGRAM_MATCH} ${posAv} )
set( posCase 0 )
RegEx( FirstImage ${j} '\*' REPLACE ${first_case} )
ForEach( i ${CASES} )
RegEx( OutputSubjDir ${outputDir} '\*' REPLACE ${i} )
###Mask images
RegEx( MASK ${INPUT_MASK_FILE} '\*' REPLACE ${i} )
RegEx( InputImage ${j} '\*' REPLACE ${i} )
set( inTAG _masked )
RegEx( CASE_Average_TAG ${Average_TAG} '\*' REPLACE ${i} )
set( maskedInput ${tempDir}/${CASE_Average_TAG}${inTAG}.nii.gz )
set( Cmd ${ImageMath} ${InputImage} -mask ${MASK} -outfile ${maskedInput} -type float)
echo( ${Cmd} )
If( ${step} < 2 )
run( output ${Cmd} )
echo( ${output} )
EndIf( ${step} < 2 )
###Median Filter
If( ${Mradius} != 0 )
set(outTAG _median )
set( MedianImage ${tempDir}/${CASE_Average_TAG}${outTAG}.nii.gz )
set( Cmd ${MedianImageFilter} --neighborhood ${Mradius},${Mradius},${Mradius} ${maskedInput} ${MedianImage} )
echo( ${Cmd} )
If( ${step} < 3 )
run( output ${Cmd} )
echo( ${output} )
EndIf( ${step} < 3 )
set( inTAG ${outTAG} )
EndIf( ${Mradius} != 0 )
###HistogramMatch
If( ${Current_HM} == TRUE )
set( outTAG ${inTAG}_hm )
set( IMG ${tempDir}/${CASE_Average_TAG}${inTAG}.nii.gz )
set( MOVING_IMG ${tempDir}/${CASE_Average_TAG}${outTAG}.nii.gz )
set( Cmd ${ImageMath} ${IMG} -matchHistogram ${FirstImage} -outfile ${MOVING_IMG} -type float)
echo( ${Cmd} )
If( ${step} < 4 )
run( output ${Cmd} )
echo( ${output} )
EndIf( ${step} < 4 )
set( inTAG ${outTAG} )
EndIf( ${Current_HM} == TRUE )
If( ${TRANSFORM_SUFFIX} != '' )
RegEx( CASE_TRANSFORM_FILE ${TRANSFORM_FILE} '\*' REPLACE ${i} )
set( RigidTransform -f ${CASE_TRANSFORM_FILE} --transform_order input-to-output )
EndIf( ${TRANSFORM_SUFFIX} != '' )
RegEx( hfield ${HField_File} '\*' REPLACE ${i} )
set( outTAG ${inTAG}_transformed )
set( transformedImage ${tempDir}/${CASE_Average_TAG}${outTAG}.nii.gz )
set( Cmd ${ResampleVolume2} ${tempDir}/${CASE_Average_TAG}${inTAG}.nii.gz ${transformedImage} -H ${hfield} -R ${Reference_Image} ${RigidTransform} )
echo( ${Cmd} )
If( ${step} < 5 )
run( output ${Cmd} )
echo( ${output} )
EndIf( ${step} < 5 )
set( inTAG ${outTAG} )
if( ${posCase} == 0 )
Set( FIRST_IMAGE ${transformedImage} )
else( ${posCase} == 0 )
Set( LIST_IMAGES ${transformedImage} ${LIST_IMAGES} )
endif( ${posCase} == 0 )
Inc( ${posCase} 1 )
Int( ${posCase} )
EndForeach( ${CASES} )
RegEx( Average_Average_TAG ${Average_TAG} '\*' REPLACE 'AverageImage' )
set( AverageOutput ${outputDir}/${Average_Average_TAG}.nii.gz )
set( Cmd ${ImageMath} ${FIRST_IMAGE} -avg ${LIST_IMAGES} -outfile ${AverageOutput} -type float )
If( ${step} < 6 )
Run( output ${Cmd} )
echo( ${output} )
EndIf( ${step} < 6 )
Set( LIST_IMAGES '' )
Inc( ${posAv} 1 )
Int( ${posAv} )
EndForEach( ${Average_INPUT_FILES} )