Hi Todd,

I think something like this should work:

fsl2ascii ${FSLDIR}/data/standard/MNI152_T1_2mm_brain.nii.gz ~/MNI152_T1_2mm_brain.txt

cat ~/MNI152_T1_2mm_brain.txt00000 | tr " " "\n" | awk '$1 != 0 && $1 !="" {print $1}' | sort > ~/MNI152_T1_2mm_brain_sorted.txt

head -n 100 ~/MNI152_T1_2mm_brain_sorted.txt

All the best,

Anderson


On 7 December 2016 at 15:51, Todd Thompson <[log in to unmask]> wrote:
Thanks, Anderson. It seems like a similar approach (count the number
of non-zero voxels, figure out the percentage you want using simple
math, threshold). It doesn't solve my wanting *exactly* <n> voxels,
unfortunately, so it sounds like Matlab/Python are going to be
required after all.

Perhaps this could be an fslmaths feature request? It seems like a
fairly common task to run something like MVPA on the top <x> voxels of
an ROI.

Thanks again,
Todd


On Wed, Dec 7, 2016 at 2:56 AM, Anderson M. Winkler
<[log in to unmask]> wrote:
> Hi Todd,
>
> The thread in the link below, from the list archive, is for a different but
> related question. Perhaps it could give some ideas with fsl2ascii and/or
> -p/-P in fslstats, have a look...
>
> https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=FSL;68f60c58.1605
>
> All the best,
>
> Anderson
>
>
> On 6 December 2016 at 16:58, Todd Thompson <[log in to unmask]> wrote:
>>
>> I'm trying to extract the top 100 voxels for each subject in a group
>> from a particular contrast, and I'm wondering what the best way of
>> doing that is. It seems like an fslmaths-y operation, but I don't see
>> an obvious flag to use.
>>
>> The best I can come up with is doing something like:
>> %get number of non-zero voxels
>> fslstats cope.nii -V
>>
>> %Do some math: 100/NumVoxels = DesiredPercent
>> fslmaths cope.nii -thrP $DesiredPercent output.nii
>>
>> And now I have an output image that will contain my voxels of interest.
>>
>> Two questions:
>> 1) Is this really the right way to do this?
>> 2) If I want exactly 100 voxels and there are voxels with duplicate
>> values in e.g., voxel positions 95-105, this could lead to an unequal
>> number of selected voxels per subject. Ideally, I'd end up with
>> exactly 100 voxels where ties are broken in an arbitrary fashion. Can
>> you see any way to do this with FSL tools?
>>
>> Thanks so much!
>> Todd
>
>