shell loops issue

Dear AFNI users,

I would like to compare severals binary maps to a reference map.
My aim is to find the maps that best overlap with this reference map (for example by counting the number of overlapping voxels with 3dOverlap and then selected the maps with the maximum value), to further process this ‘selected’ map with 3dcalc.

But I’m a bit lost with the loop and shell language issue… How should I proceed?

Thank you for your help.

Best,

Carole

Hi Carole-

There’s quite a few ways to do this… If you just want a count of the overlap, you should use 3dABoverlap. You could try something like this (bash syntax):


for aMask in mask*+tlrc.HEAD
do
    3dABoverlap -no_automask ${aMask} Reference+tlrc
done

Once you have that working, you can use the -quiet option and pipe the output to a file.

-Peter

Thank you Peter for your reply.

Yes it gives me the number of voxels overlapping for each input mask, but actually I would that it automatically select the one with the maximum overlap to then run it into a 3dcalc command.
I don’t know if it is feasible?

Thanks again,

Carole

Lots of ways to do this… perhaps the easiest would be running the 3dcalc command on each of your masks to merge it with the reference, and then using 3dBrickStat with -positive option to figure out which one to keep.


for aMask in mask*+tlrc.HEAD
do
    3dcalc -a ReferenceMask+tlrc.HEAD -b ${aMask} -prefix merged_${aMask} -expr 'ispositive(a)*ispositive(b)'
done

max=0
max_dset=" "
for aMergedMask in merged_*+tlrc.HEAD
do
     aValue=`3dBrickStat -slow -positive ${aMergedMask}`
     if [ $aValue -gt $max ]; then
          max=$aValue
          max_dset=${aMergedMask}
     fi
done
3dcopy $max_dset MaxWithReference
#optional cleanup
#rm merged*+tlrc.*

Some possibility of a typo, since I didn’t run this exact code. But the debugging should be short.

Many thanks!!!
It is working perfectly.

Carole