Dear Anderson Thank you for your reply. The chunks I have created are not of equal size. I have n chunks of 20 subjects each and one chunk with 19 subjects in it. However, I am actually not using the mean_FA but rather after deriving a study mask I am masking a target and a target skeleton and creating the individual skeletons on a subject level rather than as a all_skeletonised 4D image. Sorry, just to make it clearer, considering that mean_FA is used to derive the mask, would using unequal chunks affect the mean_FA_mask? Thanks again. Best wishes, Rali On 13 January 2013 19:03, Anderson M. Winkler <[log in to unmask]>wrote: > Dear Rali, > > Yes, your procedure should work for a mask. However, a procedure like this > for the mean_FA will only give correct results if all chunks have the same > number of subjects. If you are unfortunate and have a prime number of > subjects, then there would be no solution except discard some of them... An > alternative that doesn't require explicitly dividing the subjects into > chunks would be to increment the mask and the mean_FA for each subject > inside a loop. Below is a sketch, you can modify according to your needs > (there are probably other solutions too): > > 1) Threshold the template (or the image of any subject) using a very high > number, guaranteeing that nothing survives, so it contains only zeroes at > the beginning of the loop: > fslmaths template.nii.gz -thr 20000 toincrement.nii.gz > > 2) Make a copy, now full of ones (intersection goes with multiplication, > and 1 is neuter): > fslmaths toincrement.nii.gz -add 1 tomultiply.nii.gz > > 3) Start a counter in case you don't want to count how many subjects you > have: > c=0 > > 4) Loop over all subjects: > for i in ${list_images} ; do > fslmaths ${i} -max 0 -bin -mul tomultiply.nii.gz tomultiply.nii.gz -odt > char > fslmaths ${i} -max 0 -add toincrement.nii.gz toincrement.nii.gz -odt > double > c=$(expr ${c} + 1) > done > > 5) At the end of the loop, the mask is simply the file named > "tomultiply.nii.gz", and you can rename it (use immv for extension-free > renaming): > mv tomultiply.nii.gz mask.nii.gz > > 6) The mean FA is the file named "toincrement.nii.gz" divided by the > number of subjects (counter), with the mask applied: > fslmaths toincrement.nii.gz -div ${c} -mas mask.nii.gz mean_FA.nii.gz > > Note that a for-loop is slower than averaging over the 4D (-Tmean), but > the benefit is that you can operate in very large datasets without > splitting the sample in subgroups all of the same size. > > Hope this helps! > > All the best, > > Anderson > > > 2013/1/13 Rali Dimitrova <[log in to unmask]> > >> Dear FSL users >> >> Let say I was working on a large data set that would require to adjust >> the tbss_3 script to run chunk-wise. What I actually need as output is a >> study specific mask (mean_FA_mask). Would the following be correct: >> >> 1. Create a mean across all individual in chunk >> 1.1. merging FA_to_target into n chunks - fslmerge -t $chunk <input> >> 1.2. creating a mask for each chunk - fslmaths $chunk -max 0 >> -Tmin -bin mean_FA_mask_$chunk -odt char >> 1.3. applying the mask to each chunk - fslmaths $chunk -mas >> mean_FA_mask_$chunk $masked_chunk >> 1.4. creating a mean_FA for each chunk- fslmaths $masked_chunk -Tmean >> mean_FA_$chunk.nii.gz >> >> 2. Merging all chunks - fslmerge -t >> mean_chunk input<mean_FA_$chunk.nii.gz> >> >> 3. binarise the mean_chunk fslmaths mean_chunk >> -max 0 -Tmin -bin study_specific_mask -odt char >> >> Considering that the study_specific mask is a binary file it should not >> be affected in any way by the order of my images in each chunk I am >> merging, am I right? >> >> Your help will be greatly appreciated!! >> >> Best wishes, >> Rali >> > > -- Best wishes, Rali Dimitrova Division of Psychiatry, University of Edinburgh