This practical shows how to use |
bc for general real
number calculations (particularly divisions) and how
fslmaths can rescale and
convert images. The content is more advanced and hence optional for
those new to scripting.
- Floating point division using
To do general floating point division, you must add
var=`echo "scale=5; 5.4 / 1.9" | bc`
The scale part specifies the numbers of decimal places in the output.
Also note that the double quotes are necessary to stop the semicolon
terminating the echo command.
- Scaling and converting image intensities
The max and min intensity values for a given image can be found using
Separate and store these values by piping the output into
awk (see theory slide)
Given these values work out the
scaling factor and offset required to force the intensity range to be
within 0 to 255 (using
Apply the scaling and offset
fslmaths and then (in another call) convert the
datatype to 8bit by using:
fslmaths input output -odt char
Look here to find the cheat.