library( knitr )
knitr::opts_chunk$set(collapse = T, comment = "#>")
library(ANTsR)

Basic operations

iMath wraps some functions of ImageMath from ANTs software. Basic arithmetics (e.g., add, subtract), are built into the antsImage class capabilities, and are similar to array operations in R:

    fi  <- antsImageRead(getANTsRData("r16"), 2)
    sumfi <- fi + fi
    mulfi <- fi * 2
    #logarithm of image where non-zero
    logfi <- log(fi[fi>0])
    expfi <- exp(fi[fi>0])
    divfi <- sumfi / mulfi

Morphological operations on masks and images

The typical rule for dilation and erosion of images in ANTsR is minimum for erosion and maximum for dilation (ITK rules).

Padding or cropping an image

PadImage is a function to add/remove voxels to/from the boundaries of an image.

Distance map

Distance maps may be used for a number of purposes, including: shape analysis, skeletonization and path finding.

Denoising with anisotropic diffusion

To reduce noise without changing important parts of an image in computer vision, Perona-Malik is a promising method. Perona-Malik method to reduce noise with anisotropic diffusion is accessible via PeronaMalik operation in iMath. It requires two parameters: 1) number of iterations, and 2) conductance. This implements ITK's GradientAnisotropicDiffusionImageFilter.

The conductance parameter is described by ITK's AnisotropicDiffusionFunction: "The conductance parameter controls the sensitivity of the conductance term in the basic anisotropic diffusion equation. It affects the conductance term in different ways depending on the particular variation on the basic equation. As a general rule, the lower the value, the more strongly the diffusion equation preserves image features (such as high gradients or curvature). A high value for conductance will cause the filter to diffuse image features more readily. Typical values range from 0.5 to 2.0 for data like the Visible Human color data, but the correct value for your application is wholly dependent on the results you want from a specific data set and the number or iterations you perform."

denoised <- iMath(fi, "PeronaMalik", 10, 0.5)
invisible(plot(denoised))
# to see what the filter has removed
invisible(plot(fi - denoised))

Magnitude of gradient computation

Grad implements ITK's GradientMagnitudeRecursiveGaussian which calculates the gradient of the magnitude of an image by convolution with the first derivative of a Gaussian. Parameters are:

  grad <- iMath(fi, "Grad", 1)
  invisible(plot(grad))

Laplacian of Gaussian of an image

Laplacian implements ITK's LaplacianRecursiveGaussianImageFilter which calculates the the Laplacian of Gaussian of an image by convolving with the second derivative of a Gaussian. Parameters are:

  laplacianImage <- iMath(fi, "Laplacian", 1, 1)
  invisible(plot(laplacianImage))

Sequential operations on images

Usually it is easier to perform sequential procedures starting from left to right, instead of right to left, as one needs with functions. This has been made possible by another package that ANTsR depends on, magrittr. For example, instead of:

fi<-antsImageRead( getANTsRData("r16") , 2 )
result <- iMath(iMath(fi, "Laplacian", 1), "GD", 3)

One can do:

require(magrittr)
result <- fi %>% iMath("Laplacian",1)  %>% iMath("GD",3)

Other operations

| Operation | Example | Description | | ------------- |:-------------------------:| --------------------------:| | FillHoles |img %>% iMath("FillHoles")| Fills holes in binary object| | GetLargestComponent |img %>% iMath("GetLargestComponent")|Returns largest portion of binary object| |Normalize| img %>% iMath("Normalize") |Creates image negative| |TruncateImageIntensity| img %>% iMath("TruncateImageIntensity", 0.05, 0.95)|Trims intensities by quantiles| |Sharpen| img %>% iMath("Sharpen") | Makes edges sharper|

All iMath operations

data("iMathOps")
kable( iMathOps , caption = "Valid iMath Operations", padding = 0 )

References



neuroconductor-devel/ANTsR documentation built on April 1, 2021, 1:02 p.m.