Process image with niimath and WASM

Use image processing WASM to modify the image or add an overlay.

Controls

        Datatype information:
 -dt sets the datatype used internally for calculations (default float for all except double images)
 -odt sets the output datatype ( default is float )
 Possible datatypes are: char short int float double input
 input will set the datatype to that of the original image

New operations: (not in fslmaths)
 -bandpass    : Butterworth filter, highpass and lowpass in Hz,TR in seconds (zero-phase 2*2nd order filtfilt)
 -bptfm           : Same as bptf but does not remove mean (emulates fslmaths < 5.0.7)
 -ceil                    : round voxels upwards to the nearest integer
 -crop       : remove volumes, starts with 0 not 1! Inputting -1 for a size will set it to the full range
 -detrend                 : remove linear trend (and mean) from input
 -demean                  : remove average signal across volumes (requires 4D input)
 -edt                     : estimate Euler Distance Transform (distance field). Assumes isotropic input
 -floor                    : round voxels downwards to the nearest integer
 -mod                     : modulus fractional remainder - same as '-rem' but includes fractions
 -p              : set maximum number of parallel threads. DISABLED: recompile for OpenMP support
 -resize      : grow (>1) or shrink (<1) image. Method  (0=nearest,1=linear,2=spline,3=Lanczos,4=Mitchell)
 -round                   : round voxels to the nearest integer
 -sobel                   : fast edge detection
 -sobel_binary              : sobel creating binary edge
 -tensor_2lower           : convert FSL style upper triangle image to NIfTI standard lower triangle order
 -tensor_2upper           : convert NIfTI standard lower triangle image to FSL style upper triangle order
 -tensor_decomp_lower     : as tensor_decomp except input stores lower diagonal (AFNI, ANTS, Camino convention)
 -trunc                   : truncates the decimal value from floating point value and returns integer value
 -unsharp     : edge enhancing unsharp mask (sigma in mm, not voxels; 1.0 is typical for amount (scl))
 -dog         : difference of gaussian with zero-crossing edges (positive and negative sigma mm)
 -dogr        : as dog, without zero-crossing (raw rather than binarized data)
 -dogx        : as dog, zero-crossing for 2D sagittal slices
 -dogy        : as dog, zero-crossing for 2D coronal slices
 -dogz        : as dog, zero-crossing for 2D axial slices
 --compare           : report if images are identical, terminates without saving new image
 filename.nii             : mimic fslhd (can also export to a txt file: 'niimath T1.nii 2> T1.txt') report header and terminate without saving new image

Binary operations:
  (some inputs can be either an image or a number)
 -add   : add following input to current image
 -sub   : subtract following input from current image
 -mul   : multiply current image by following input
 -div   : divide current image by following input
 -rem   : modulus remainder - divide current image by following input and take remainder
 -mas   : use (following image>0) to mask current image
 -thr   : use following number to threshold current image (zero anything below the number)
 -thrp  : use following percentage (0-100) of ROBUST RANGE to threshold current image (zero anything below the number)
 -thrP  : use following percentage (0-100) of ROBUST RANGE of non-zero voxels and threshold below
 -uthr  : use following number to upper-threshold current image (zero anything above the number)
 -uthrp : use following percentage (0-100) of ROBUST RANGE to upper-threshold current image (zero anything above the number)
 -uthrP : use following percentage (0-100) of ROBUST RANGE of non-zero voxels and threshold above
 -clamp : use following percentage (0-100) of ROBUST RANGE to threshold current image (anything below set to this threshold)
 -uclamp: use following percentage (0-100) of ROBUST RANGE to threshold current image (anything above set to this threshold)
 -max   : take maximum of following input and current image
 -min   : take minimum of following input and current image
 -seed  : seed random number generator with following number
 -restart : replace the current image with input for future processing operations
 -save : save the current working image to the input filename
 -inm  :  (-i i ip.c) intensity normalisation (per 3D volume mean)
 -ing  :  (-I i ip.c) intensity normalisation, global 4D mean)
 -s  : create a gauss kernel of sigma mm and perform mean filtering

Basic unary operations:
 -exp   : exponential
 -log   : natural logarithm
 -sin   : sine function
 -cos   : cosine function
 -tan   : tangent function
 -asin  : arc sine function
 -acos  : arc cosine function
 -atan  : arc tangent function
 -sqr   : square
 -sqrt  : square root
 -recip : reciprocal (1/current image)
 -abs   : absolute value
 -bin   : use (current image>0) to binarise
 -binv  : binarise and invert (binarisation and logical inversion)
 -fillh : fill holes in a binary mask (holes are internal - i.e. do not touch the edge of the FOV)
 -fillh26 : fill holes using 26 connectivity
 -index : replace each nonzero voxel with a unique (subject to wrapping) index number
 -grid   : add a 3D grid of intensity  with grid spacing 
 -edge  : edge strength
 -tfce   : enhance with TFCE, e.g. -tfce 2 0.5 6 (maybe change 6 to 26 for skeletons)
 -tfceS       : show support area for voxel (X,Y,Z)
 -nan   : replace NaNs (improper numbers) with 0
 -nanm  : make NaN (improper number) mask with 1 for NaN voxels, 0 otherwise
 -rand  : add uniform noise (range 0:1)
 -randn : add Gaussian noise (mean=0 sigma=1)
 -range : set the output calmin/max to full data range

Matrix operations:
 -tensor_decomp : convert a 4D (6-timepoint )tensor image into L1,2,3,FA,MD,MO,V1,2,3 (remaining image in pipeline is FA)

Kernel operations (set BEFORE filtering operation if desired):
 -kernel 3D : 3x3x3 box centered on target voxel (set as default kernel)
 -kernel 2D : 3x3x1 box centered on target voxel
 -kernel box         : all voxels in a cube of width  mm centered on target voxel
 -kernel boxv        : all voxels in a cube of width  voxels centered on target voxel, CAUTION: size should be an odd number
 -kernel boxv3    : all voxels in a cuboid of dimensions X x Y x Z centered on target voxel, CAUTION: size should be an odd number
 -kernel gauss      : gaussian kernel (sigma in mm, not voxels)
 -kernel sphere      : all voxels in a sphere of radius  mm centered on target voxel
 -kernel file    : use external file as kernel

Spatial Filtering operations: N.B. all options apart from -s use the default kernel or that _previously_ specified by -kernel
 -dilM    : Mean Dilation of non-zero voxels
 -dilD    : Maximum Dilation of non-zero voxels (emulating output of fslmaths 6.0.1, max not modal)
 -dilF    : Maximum filtering of all voxels
 -dilall  : Apply -dilM repeatedly until the entire FOV is covered
 -ero     : Erode by zeroing non-zero voxels when zero voxels found in kernel
 -eroF    : Minimum filtering of all voxels
 -fmedian : Median Filtering 
 -fmean   : Mean filtering, kernel weighted (conventionally used with gauss kernel)
 -fmeanu  : Mean filtering, kernel weighted, un-normalized (gives edge effects)
 -s  : create a gauss kernel of sigma mm and perform mean filtering
 -subsamp2  : downsamples image by a factor of 2 (keeping new voxels centered on old)
 -subsamp2offc  : downsamples image by a factor of 2 (non-centered)

Dimensionality reduction operations:
  (the T can be replaced by X, Y or Z to collapse across a different dimension)
 -Tmean   : mean across time
 -Tstd    : standard deviation across time
 -Tmax    : max across time
 -Tmaxn   : time index of max across time
 -Tmin    : min across time
 -Tmedian : median across time
 -Tperc  : nth percentile (0-100) of FULL RANGE across time
 -Tar1    : temporal AR(1) coefficient (use -odt float and probably demean first)

Basic statistical operations:
 -pval    : Nonparametric uncorrected P-value, assuming timepoints are the permutations; first timepoint is actual (unpermuted) stats image
 -pval0   : Same as -pval, but treat zeros as missing data
 -cpval   : Same as -pval, but gives FWE corrected P-values
 -ztop    : Convert Z-stat to (uncorrected) P
 -ptoz    : Convert (uncorrected) P to Z
 -rank    : Convert data to ranks (over T dim)
 -ranknorm: Transform to Normal dist via ranks

Multi-argument operations:
 -roi         : zero outside roi (using voxel coordinates). Inputting -1 for a size will set it to the full image extent for that dimension
 -bptf    : (-t in ip.c) Bandpass temporal filtering; nonlinear highpass and Gaussian linear lowpass (with sigmas in volumes, not seconds); set either sigma<0 to skip that filter
 -roc   [4Dnoiseonly]  : take (normally binary) truth and test current image in ROC analysis against truth.  is usually 0.05 and is limit of Area-under-ROC measure FP axis.  is a text file of the ROC curve (triplets of values: FP TP threshold). If the truth image contains negative voxels these get excluded from all calculations. If  is positive then the [4Dnoiseonly] option needs to be set, and the FP rate is determined from this noise-only data, and is set to be the fraction of timepoints where any FP (anywhere) is seen, as found in the noise-only 4d-dataset. This is then controlling the FWE rate. If  is negative the FP rate is calculated from the zero-value parts of the  image, this time averaging voxelwise FP rate over all timepoints. In both cases the TP rate is the average fraction of truth=positive voxels correctly found