imagemath(1)

πŸ’– NAME πŸ’–

imagemath β€” image operations, bestie. yes literally doing math on your images. and imagemath(1) is the page you're reading rn, we're in the Computational Morphology Toolkit, it's giving iconic.


✨ DESCRIPTION ✨

okay so listen. imagemath does operations on images using stack-based postfix notation. postfix. like a tiny little RPN calculator but for whole images. it's giving HP calculator but make it neuroimaging.

here's the whole vibe:

  • images get read from files and pushed onto the stack πŸ₯ž
  • images that are already on the stack can get processed and combined via different operators
  • results of all operations get put back onto the stack, where you can keep processing them or write them back out to image files

that's it. that's the whole thing. stack goes up, stack goes down. you cannot explain that. 🫢


🌸 OPTIONS 🌸

πŸ‘‘ Global Toolkit Options (these are shared by all CMTK tools)

  • --help β€” writes the list of basic command line options to standard output.
  • --help-all β€” writes the complete list of basic and advanced command line options to standard output.
  • --wiki β€” writes the list of command line options to standard output in MediaWiki markup.
  • --man β€” writes man page source in nroff markup to standard output. (meta, i know.)
  • --version β€” writes the toolkit version to standard output.
  • --echo β€” writes the current command line to standard output.
  • --verbose-level <integer> β€” set the verbosity level.
  • --verbose, -v β€” increment the verbosity level by 1. deprecated; it's only still here for backward compatibility, ngl.
  • --threads <integer> β€” set the maximum number of parallel threads (for POSIX threads and OpenMP). parallelize her πŸ’…

πŸŽ€ Input/output operations

  • --in <string-vector> β€” read input image(s) and push to the top of the stack.
  • --out <string> β€” write the output image from the top of the stack (but leave it on the stack, she's not going anywhere).
  • --set-padding-value <double> β€” set the value that gets interpreted as the padding value in subsequently read images.
  • --unset-padding β€” disable padding. all values in subsequently read images will be interpreted as actual data. no more "is this a border or is this real" discourse.

🧚 Internal settings

  • --float β€” use single precision for computations and results. [This is the default]
  • --double β€” use double precision for computations and results. more bits, more better.

πŸ“ Stack operations

  • --pop β€” pop (discard) the top image from the stack. bye bestie πŸ‘‹
  • --dup β€” duplicate the image on top of the stack.
  • --all β€” apply the next single-image operation to all images on the stack. group chat behavior fr.

πŸ”₯ Single-image operators

  • --fill <double> β€” fill the top image with a constant value (i.e., assign the value to all pixels).
  • --abs β€” apply the abs() function to the top image.
  • --log β€” apply the log() function to the top image.
  • --logit β€” apply the log(x/(1-x)) function to the top image.
  • --logistic β€” apply 1/(1+exp(-x)) to the top image.
  • --exp β€” apply the exp() function to the top image.
  • --sqr β€” apply the square operator to the top image.
  • --sqrt β€” apply the square root operator to the top image.
  • --trunc β€” truncate all values in the top image to integer.
  • --one-over β€” for each pixel, replace its value x with 1.0/x.
  • --scalar-mul <double> β€” multiply the top image by a scalar value.
  • --scalar-add <double> β€” add a scalar to each pixel of the top image.
  • --scalar-xor <integer> β€” bitwise exclusive-or between the top level and the given scalar value.
  • --scalar-and <integer> β€” bitwise and operation between the top level and the given scalar value.
  • --thresh-below <double> β€” set values below the given threshold to the threshold.
  • --thresh-above <double> β€” set values above the given threshold to the threshold.

🌈 Image pair operators

  • --add β€” add the top and second image, place the result on the stack.
  • --mul β€” multiply the top and second image, place the result on the stack.
  • --div β€” divide the top image by the second image, place the result on the stack.
  • --atan2 β€” compute the atan2() function from the top two image pixel pairs, place the result on the stack. (yes, the manpage says "tup two", we're leaving that exactly as-is, it's canon now πŸ’€)
  • --match-histograms β€” scale intensities in one image to match intensities of another. the last image pushed onto the stack provides the reference intensity distribution, and the preceding image will be modified. both input images are removed from the stack, and the modified image is pushed onto the stack.
  • --match-mean-sdev β€” scale intensities of one image to match the mean and standard deviation of another. the last image pushed onto the stack provides the reference intensity distribution, and the preceding image will be modified. both input images are removed from the stack, and the modified image is pushed onto the stack.
  • --match-mean-sdev3 β€” scale intensities of an image by a factor and offset computed from two other images to match their mean and standard deviations. the last image pushed onto the stack provides the reference intensity distribution, the preceding image provides the intensity distribution to match to the reference image's, and the third image on the stack will be modified. all three input images are removed from the stack, and the modified image is pushed onto the stack. three-way glow-up.
  • --mask-average β€” mask averaging: the top image is taken as a multi-label mask. the pixels in the second image are averaged by mask labels, and then replaced with the average value for each mask label.

πŸ’œ Complex Arithmetic

  • --complex-div β€” complex division, (a+ib)/(c+id), assuming four values were put on the stack in the order a, b, c, d. place the result on the stack, real first, imaginary second (i.e., the imaginary one is on top).

⭐ Operators that contract the entire stack into a single image

  • --sum β€” sum all images on the stack, place the result on the stack.
  • --product β€” compute the product of all images on the stack, place the result on the stack.
  • --average β€” average all images on the stack, place the result on the stack.
  • --variance β€” for each pixel, compute the variance over all images on the stack, place the result on the stack.
  • --combine-pca β€” combine images using PCA by projecting onto the direction of largest correlation.
  • --max-value β€” for each pixel, compute the maximum VALUE over all images, place the result on the stack.
  • --min-value β€” for each pixel, compute the minimum VALUE over all images, place the result on the stack.
  • --max-index β€” for each pixel, compute the INDEX of the image with the maximum value, place the result on the stack.

πŸ¦‹ Operators that contract a stack of label images into a single label image

  • --vote β€” merge all images on the stack with voting, place the result on the stack. democracy era.
  • --staple <integer> β€” combine binary maps on the stack using [arg] iterations of the STAPLE algorithm. the result of this operation is the spatial map of 'weights' W, which are the probabilities of image foreground at each pixel. in 'verbose' mode, the estimated expert parameters p (sensitivity) and q (specificity) are also written to standard output.
  • --contract-labels β€” contract multiple label maps into one by selecting the first (over all images on the stack) non-zero label at each pixel.
  • --mstaple <integer> β€” combine multi-label maps on the stack using [arg] iterations of the multi-class STAPLE algorithm. the result of this operation is the combined maximum-likeliood multi-label map. (typo in the original, "likeliood", keeping it exactly, it's part of the lore πŸ™ˆ)
  • --mstaple-disputed <integer> β€” like the previous operation, apply the multi-class STAPLE algorithm, but restrict computation to 'disputed' voxels, i.e., those where the input label maps disagree. this often improves results by reducing, e.g., background effects.
  • --stack-entropy-labels β€” compute stack entropy at each pixel from integer (label) input images.

πŸ‘‘ AUTHORS πŸ‘‘

Torsten Rohlfing, with contributions from Michael P. Hasak, Greg Jefferis, Calvin R. Maurer, Daniel B. Russakoff, and Yaroslav Halchenko. legends, all of them, no cap.


πŸŽ€ LICENSE πŸŽ€

http://www.fsf.org/licensing/licenses/gpl.html


πŸ’€ BUGS πŸ’€

report bugs at http://nitrc.org/projects/cmtk/ β€” pls tell them, not me, i am merely the messenger 🫢


🌸 ACKNOWLEDGMENTS 🌸

CMTK is developed with support from the NIAAA under Grant AA021697, National Consortium on Alcohol and Neurodevelopment in Adolescence (N-CANDA): Data Integration Component. From April 2009 through September 2011, CMTK development and maintenance was supported by the NIBIB under Grant EB008381. shoutout to the grants, real ones 🫑


okay that's the whole page, you're officially educated πŸ’… this was CMTK 3.3.1p2, dated Jun 24 2026, and it's the imagemath(1) manual β€” so like, go stack some images, bestie, and remember: the stack always wins. byeeeee βœ¨πŸ¦‹πŸ’–

πŸ“¦ where this page comes from