IMAGEMATH(1) User Commands IMAGEMATH(1)

NAME¶

ImageMath - part of ANTS registration suite

SYNOPSIS¶

ImageMath ImageDimension <OutputImage.ext> [operations and inputs] <Image1.ext> <Image2.ext>

DESCRIPTION¶

Usage Information

ImageDimension: 2 or 3 (for 2 or 3 dimensional operations). ImageDimension: 4 (for operations on 4D file, e.g. time-series data). Operator: See list of valid operators below. The last two arguments can be an image or float value NB: Some options output text files

Mathematical Operations:¶

: Multiply --- use vm for vector multiply
+
: Add --- use v+ for vector add
-
: Subtract --- use v- for vector subtract
/
: Divide
^
: Power
: voxelwise max
: Take exponent exp(imagevalue*value)
: add image-b to image-a only over points where image-a has zero values
: replace image-a pixel with image-b pixel if image-b pixel is non-zero
: absolute value
: Sums up values in an image or in image1*image2 (img2 is the probability mask)
: Average of values in an image or in image1*image2 (img2 is the probability mask)
: Sums up volumetrically weighted values in an image or in image1*image2 (img2 is the probability mask)
: Computes result=1./(1.+exp(-1.0*( pix1-0.25)/pix2))
: Produce image negative

Spatial Filtering:¶

: Project an image along axis a, which-projection=0(sum, 1=max, 2=min)
: Smooth with Gaussian of sigma = s
: Morphological Dilation with radius s
: Morphological Erosion with radius s
: Morphological Opening with radius s
: Morphological Closing with radius s
: Grayscale Dilation with radius s
: Grayscale Erosion with radius s
: Grayscale Opening with radius s
: Grayscale Closing with radius s
Optional-Input-Image2 Blob-2-out.nii.gz N-Blobs-To-Match : blob detection by searching for local extrema of the Laplacian of the Gassian (LoG)
Example matching 6 best blobs from 2 images: ImageMath 2 blob.nii.gz BlobDetector image1.nii.gz 1000 image2.nii.gz blob2.nii.gz 6
MatchBlobs Image1.ext Image1LM.ext Image2.ext

Transform Image: Translate InImage.ext x [ y z ]

Time Series Operations:¶

Also outputs a comp-corr + global signal corrected 4D image as well as a 3D image measuring the time series variance. Requires a label image with label 1 identifying voxels in the brain.
\${out}seg.nii.gz 1 3 : Outputs average global, CSF and WM signals. Requires a label image with 3 labels , csf, gm , wm .
: ThreeTissueConfounds 4D_TimeSeries.nii.gz LabeLimage.nii.gz csf-label wm-label
TimeSeriesSubset : Outputs n 3D image sub-volumes extracted uniformly from the input time-series 4D image.
: TimeSeriesSubset 4D_TimeSeries.nii.gz n
TimeSeriesDisassemble : Outputs n 3D image volumes for each time-point in time-series 4D image.
: TimeSeriesDisassemble 4D_TimeSeries.nii.gz
TimeSeriesAssemble : Outputs a 4D time-series image from a list of 3D volumes.
: TimeSeriesAssemble time_spacing time_origin *images.nii.gz
TimeSeriesToMatrix : Converts a 4D image + mask to matrix (stored as csv file) where rows are time and columns are space .
: TimeSeriesToMatrix 4D_TimeSeries.nii.gz mask
TimeSeriesSimpleSubtraction : Outputs a 3D mean pair-wise difference list of 3D volumes.
: TimeSeriesSimpleSubtraction image.nii.gz
TimeSeriesSurroundSubtraction : Outputs a 3D mean pair-wise difference list of 3D volumes.
: TimeSeriesSurroundSubtraction image.nii.gz
TimeSeriesSincSubtraction : Outputs a 3D mean pair-wise difference list of 3D volumes.
: TimeSeriesSincSubtraction image.nii.gz
SplitAlternatingTimeSeries : Outputs 2 3D time series
: SplitAlternatingTimeSeries image.nii.gz
leverage, here, is the difference of the time-point image from the average of the n images. the normalized leverage is = average( sum_k abs(Leverage(t)-Leverage(k)) )/Leverage(t).
: ComputeTimeSeriesLeverage 4D_TimeSeries.nii.gz k_neighbors
SliceTimingCorrection : Outputs a slice-timing corrected 4D time series
: SliceTimingCorrection image.nii.gz sliceTiming [sinc / bspline] [sincRadius=4 / bsplineOrder=3]
PASL : computes the PASL model of CBF

f = ?rac{ lambda DeltaM }

{
2 alpha M_0 TI_1 exp( - TI_2 / T_{1a} ) }
: PASL 3D/4D_TimeSeries.nii.gz BoolFirstImageIsControl M0Image parameter_list.txt
pCASL : computes the pCASL model of CBF f = ?rac{ lambda DeltaM R_{1a} }
{
2 alpha M_0 [ exp( - w R_{1a} ) - exp( -w ( au + w ) R_{1a}) ] }
: pCASL 3D/4D_TimeSeries.nii.gz parameter_list.txt
PASLQuantifyCBF : Outputs a 3D CBF image in ml/100g/min from a magnetization ratio image
: PASLQuantifyCBF mag_ratio.nii.gz [TI1=700] [TI2=1900] [T1blood=1664] [Lambda=0.9] [Alpha=0.95] [SliceDelay-45]

Tensor Operations:¶

4DTensorTo3DTensor
: Outputs a 3D_DT_Image with the same information.
: 4DTensorTo3DTensor 4D_DTImage.ext
: Outputs a 3D_DT_Image with the same information as component images.
: ComponentTo3DTensor component_image_prefix[xx,xy,xz,yy,yz,zz] extension
: Outputs a component images.
: ExtractComponentFrom3DTensor dtImage.ext which={xx,xy,xz,yy,yz,zz}
ExtractVectorComponent: Produces the WhichVec component of the vector
: ExtractVectorComponent VecImage WhichVec
: Produces RGB values identifying principal directions
: TensorColor DTImage.ext
:
: TensorFA DTImage.ext
:
:
: TensorFANumerator DTImage.ext
: Will write the DT image back out ... tests I/O processes for consistency.
: TensorIOTest DTImage.ext
: Mean of the eigenvalues
: TensorMeanDiffusion DTImage.ext
: Mean of the two smallest eigenvalues
: Largest eigenvalue, equivalent to TensorEigenvalue DTImage.ext 2
: TensorAxialDiffusion DTImage.ext
: Gets a single eigenvalue 0-2, where 0 = smallest, 2 = largest
: TensorEigenvalue DTImage.ext WhichInd
: Produces vector field identifying one of the principal directions, 2 = largest eigenvalue
: TensorToVector DTImage.ext WhichVec
TensorToVectorComponent: 0 => 2 produces component of the principal vector field (largest eigenvalue). 3 = 8 => gets values from the tensor
: TensorToVectorComponent DTImage.ext WhichVec
: Mask a tensor image, sets background tensors to zero or to isotropic tensors with specified mean diffusivity
: TensorMask DTImage.ext mask.ext [ backgroundMD = 0 ]
: Create ND field from N input scalar images
: FuseNImagesIntoNDVectorField imagex imagey imagez

Label Fusion:¶

MajorityVoting : Select label with most votes from candidates
Usage: MajorityVoting LabelImage1.nii.gz .. LabelImageN.nii.gz
CorrelationVoting : Select label with local correlation weights
Usage: CorrelationVoting Template.ext IntenistyImages* LabelImages* {Optional-Radius=5}
STAPLE : Select label using STAPLE method
Usage: STAPLE confidence-weighting LabelImages* Note: Gives probabilistic output (float)
MostLikely : Select label from from maximum probabilistic segmentations
Usage: MostLikely probabilityThreshold ProbabilityImages*
AverageLabels : Select label using STAPLE method
Usage: STAPLE LabelImages* Note: Gives probabilistic output (float)

Image Metrics & Info:¶

PearsonCorrelation: r-value from intesities of two images
Usage: PearsonCorrelation image1.ext image2.ext {Optional-mask.ext}
NeighborhoodCorrelation: local correlations
NormalizedCorrelation: r-value from intesities of two images
Usage: NormalizedCorrelation image1.ext image2.ext {Optional-image-mask}
Demons:
Usage: Demons image1.ext image2.ext
Mattes: mutual information
Usage: Mattes image1.ext image2.ext {Optional-number-bins=32} {Optional-image-mask}

Unclassified Operators:¶

ReflectionMatrix : Create a reflection matrix about an axis
out.mat ReflectionMatrix image_in axis
MakeAffineTransform : Create an itk affine transform matrix ClosestSimplifiedHeaderMatrix : does what it says ... image-in, image-out Byte : Convert to Byte image in [0,255]
CompareHeadersAndImages: Tries to find and fix header errors. Outputs a repaired image with new header.
Never use this if you trust your header information.
: CompareHeadersAndImages Image1 Image2
ConvertImageSetToMatrix: Each row/column contains image content extracted from mask applied to images in *img.nii
: ConvertImageSetToMatrix rowcoloption Mask.nii *images.nii
ConvertImageSetToMatrix output can be an image type or csv file type.
RandomlySampleImageSetToCSV: N random samples are selected from each image in a list
: RandomlySampleImageSetToCSV N_samples *images.nii
RandomlySampleImageSetToCSV outputs a csv file type.
FrobeniusNormOfMatrixDifference: take the difference between two itk-transform matrices and then compute the frobenius norm
: FrobeniusNormOfMatrixDifference mat1 mat2
ConvertImageSetToEigenvectors: Each row/column contains image content extracted from mask applied to images in *img.nii
: ConvertImageSetToEigenvectors N_Evecs Mask.nii *images.nii
ConvertImageSetToEigenvectors output will be a csv file for each label value > 0 in the mask.
: Writes voxel values to a file
: ConvertImageToFile imagevalues.nii {Optional-ImageMask.nii}
: Converts landmark file between formats. See ANTS.pdf for description of formats.
: ConvertLandmarkFile InFile.txt
: ImageMath 3 outfile.vtk ConvertLandmarkFile infile.txt
:
: ConvertToGaussian TValueImage sigma-float
: The vector contains image content extracted from a mask. Here the vector is returned to its spatial origins as image content
: ConvertVectorToImage Mask.nii vector.nii
: In voxels, compute update that makes Image2 more like Image1.
: CorrelationUpdate Image1.ext Image2.ext RegionRadius
: The where function from IDL
: CountVoxelDifference Image1 Image2 Mask
:
: CorruptImage Image NoiseLevel Smoothing
: Danielson Distance Transform
MaurerDistance : Maurer distance transform (much faster than Danielson)
: MaurerDistance inputImage {foreground=1}
: Outputs DiceAndMinDistSum and Dice Overlap to text log file + optional distance image
: DiceAndMinDistSum LabelImage1.ext LabelImage2.ext OptionalDistImage
EnumerateLabelInterfaces:
: EnumerateLabelInterfaces ImageIn ColoredImageOutname NeighborFractionToIgnore
: for sparse estimation
: ClusterThresholdVariate image mask MinClusterSize
: Extracts slice number from last dimension of volume (2,3,4) dimensions
: ExtractSlice volume.nii.gz slicetoextract
FastMarchingSegmentation: final output is the propagated label image. Optional stopping value: higher values allow more distant propagation
: FastMarchingSegmentation speed/binaryimagemask.ext initiallabelimage.ext Optional-Stopping-Value
: Parameter = ratio of edge at object to edge at background; --
Parameter = 1 is a definite hole bounded by object only, 0.99 is close Default of parameter > 1 will fill all holes
: FillHoles Image.ext parameter
: very simple inpainting --- assumes zero values should be inpainted
: InPaint #iterations
: anisotropic diffusion w/varying conductance param (0.25 in example below)
: PeronaMalik image #iterations conductance
: convolve input image with kernel image
: Convolve inputImage kernelImage {normalize=1}
: replace non-finite values with finite-value (default = 0)
: Finite Image.exdt {replace-value=0}
:
: LabelSurfaceArea ImageIn {MaxRad-Default=1}
: Replaces values greater than %ofMax*Max to the value %ofMax*Max
: FlattenImage Image %ofMax
: Get the largest object in an image
: GetLargestComponent InputImage {MinObjectSize}
: Gradient magnitude with sigma s (if normalize, then output in range [0, 1])
: Grad Image.ext s normalize?
:
: HistogramMatch SourceImage ReferenceImage {NumberBins-Default=255} {NumberPoints-Default=64} {useThresholdAtMeanIntensity=false}
:
: RescaleImage InputImage min max
:
: WindowImage InputImage windowMinimum windowMaximum outputMinimum outputMaximum
:
: NeighborhoodStats inputImage whichStat radius whichStat: 1 = min, 2 = max, 3 = variance, 4 = sigma, 5 = skewness, 6 = kurtosis, 7 = entropy
: computes the inverse-consistency of two deformations and write the inverse consistency error image
: InvId VectorFieldName VectorFieldName
: replicate a ND displacement to a ND+1 image
: ReplicateDisplacement VectorFieldName TimeDims TimeSpacing TimeOrigin
: replicate a ND image to a ND+1 image
: ReplicateImage ImageName TimeDims TimeSpacing TimeOrigin
: shift image slices by one
: ShiftImageSlicesInTime ImageName shift-amount-default-1 shift-dim-default-last-dim
: Compute volumes / masses of objects in a label image. Writes to text file
: LabelStats labelimage.ext valueimage.nii
: Laplacian computed with sigma s (if normalize, then output in range [0, 1])
: Laplacian Image.ext s normalize?
: Canny edge detector
: Canny Image.ext sigma lowerThresh upperThresh
: Computes the Lipschitz norm of a vector field
: Lipschitz VectorFieldName
:
: MakeImage SizeX SizeY {SizeZ};
: Computes the magnetization transfer ratio ( (M0-M1)/M0 ) and truncates values to [0,1]
: MTR M0Image M1Image [MaskImage];
: Normalize to [0,1]. Option instead divides by average value. If opt is a mask image, then we normalize by mean intensity in the mask ROI.
: Normalize Image.ext opt
: If Pad-Number is negative, de-Padding occurs
:
: SigmoidImage ImageIn [alpha=1.0] [beta=0.0]
:
: Sharpen ImageIn
:
: ReferenceImageSpace ImageToCenter
: Solves Poisson's equation in a designated region using non-zero sources
: PoissonDiffusion inputImage labelImage [sigma=1.0] [regionLabel=1] [numberOfIterations=500] [convergenceThreshold=1e-10]
PropagateLabelsThroughMask: Final output is the propagated label image. Optional stopping value: higher values allow more distant propagation
0/1/2
=> 0, no topology constraint, 1 - strict topology constraint, 2 - no handles
:
: PValueImage TValueImage dof
RemoveLabelInterfaces:
: RemoveLabelInterfaces ImageIn
ReplaceVoxelValue: replace voxels in the range [a,b] in the input image with c
: ReplaceVoxelValue inputImage a b c
: computes anatomical locations, cluster size and mass of a stat image which should be in the same physical space (but not nec same resolution) as the label image.
: ROIStatistics LabelNames.txt labelimage.ext valueimage.nii
:
: SetOrGetPixel ImageIn Get/Set-Value IndexX IndexY {IndexZ}
: ImageMath 2 outimage.nii SetOrGetPixel Image Get 24 34; Gets the value at 24, 34
: ImageMath 2 outimage.nii SetOrGetPixel Image 1.e9 24 34; This sets 1.e9 as the value at 23 34
You can also pass a boolean at the end to force the physical space to be used
: sets spacing for last dimension
: SetTimeSpacing Image.ext tspacing
: sets spacing for last dimension
: SetTimeSpacingWarp Warp.ext tspacing
: Will put 2 images in the same volume
: Stack Image1.ext Image2.ext
: See the code
: ThresholdAtMean Image %ofMean
:
: TileImages NumColumns ImageList*
:
: TriPlanarView ImageIn.nii.gz PercentageToClampLowIntensity PercentageToClampHiIntensity x-slice y-slice z-slice
TruncateImageIntensity:
: TruncateImageIntensity InputImage.ext {lowerQuantile=0.05} {upperQuantile=0.95} {numberOfBins=65} {binary-maskImage}
: The where function from IDL
: Where Image ValueToLookFor maskImage-option tolerance
 October 2017 ImageMath 2.2.0