AFNI Message Board

Dear AFNI users-

We are very pleased to announce that the new AFNI Message Board framework is up! Please join us at:

https://discuss.afni.nimh.nih.gov

Existing user accounts have been migrated, so returning users can login by requesting a password reset. New users can create accounts, as well, through a standard account creation process. Please note that these setup emails might initially go to spam folders (esp. for NIH users!), so please check those locations in the beginning.

The current Message Board discussion threads have been migrated to the new framework. The current Message Board will remain visible, but read-only, for a little while.

Sincerely, AFNI HQ

History of AFNI updates  

|
August 28, 2015 08:15AM
There may be a smoother way with a single command, but otherwise how about putting the below into a tcsh file, such as "do_replacement.tcsh". You can replace the first four file names with the necessary information for you-- the input mask name and datafile name; and then the output mean- and std-replaced file names. Then, you can run it from the commandline with:
$ tcsh do_replacement.tcsh

At the moment, it will replace datafile voxels in the mask with either mean or std, *and* keep the values outside the mask what they originally were. You didn't specify in your post anything about the values outside the mask, so I left them unchanged. You can remove those if you want (-> mask them out) by getting rid of the "+ a * not(b)" part of the 3dcalc commands.

If you want, you can enter the file names from the commandline by replacing the four input/output file names ("MASK_NAME", "DATA_NAME", etc.) with $1, $2, $3, and $4 (literally, those two characters). Then, you can you the four file names you want as commandline arguments when you run the program, such as:
$ tcsh do_replacement.tcsh "MASK_NAME" "DATA_NAME" ...
That might be easier for scripting, if you wish.

--pt

-------------------------------- copy below into "do_replacement.tcsh" -----------------------------------
#/bin/tcsh

# input files: first mask, then data file
set my_mask     = "MASK_NAME"
set my_datafile = "DATA_NAME"

# output files: first mean-replaced, then std-replaced one
set my_out_mean = "NEW_MEAN_NAME"
set my_out_std  = "NEW_STD_NAME"

# ------------------------------------------------------------------

# calculate both mean and std
set A  = `3dROIstats -quiet -sigma -mask $my_mask  $my_datafile`
# separate out two returned values from above
set mask_mean = $A[1]
set mask_std  = $A[2]

# replace values in mask with mean; keep values in datafile outside mask
3dcalc                    \
    -a $my_datafile       \
    -b $my_mask           \
    -expr "$mask_mean * step(b) + a * not(b)" \
    -prefix $my_out_mean \
    -overwrite

# replace values in mask with mean; keep values in datafile outside mask
3dcalc                    \
    -a $my_datafile       \
    -b $my_mask           \
    -expr "$mask_std * step(b) + a * not(b)" \
    -prefix $my_out_std  \
    -overwrite
Subject Author Posted

calculations within a mask

Simone August 28, 2015 07:35AM

Re: calculations within a mask

ptaylor August 28, 2015 08:15AM

Re: calculations within a mask

Simone August 28, 2015 01:53PM

Re: calculations within a mask

Daniel Glen August 28, 2015 05:54PM