Dear @jdtournier ,
I hope you are doing great. I am trying to mask bright intensity around FA image. I can erode the mask. But, sometimes, brain areas also get masked out. So, I would like to threshold bright intensity areas at the boundary that are not cortex areas. For example, I have label image having 1-40 brain areas and 1-20 are cortex that are at the boundary. I would like to threshold those areas by FA value 0.4, so that greater than 0.4 gets masked out.

Right now, I create cortex mask and create FA from that mask and threshold by 0.4 globally:

mrthreshold labels.nii.gz -abs 20 -comparison le mask20.nii.gz

I am wondering if you can help me loop it in something like label-wise:

for N in {1..20} ; do
  mrcalc labels.nii.gz $N -eq - | mrthreshold fa.nii.gz ..................

I am very much thankful to you.

Best Regards,