compute similarity metric between two images as image is rotated about its center w/or w/o optimization
invariantImageSimilarity(in_image1, in_image2, localSearchIterations = 0,
metric = "MI", thetas = seq(from = 0, to = 360, length.out = 5),
thetas2 = seq(from = 0, to = 360, length.out = 5), thetas3 = seq(from = 0,
to = 360, length.out = 5), scaleImage = 1, doReflection = 0, txfn = NA,
transform = c("Affine", "Similarity", "Rigid"))
reference image
moving image
integer controlling local search in multistart
which metric MI or GC (string)
numeric vector of search angles in degrees
numeric vector of search angles in degrees around principal axis 2 (3D)
numeric vector of search angles in degrees around principal axis 3 (3D)
global scale
reflect image about principal axis
if present, write optimal tx to .mat file
Rigid, Similarity or Affine transform
dataframe with metric values and transformation parameters
# NOT RUN {
fi<-antsImageRead( getANTsRData("r16") )
mi<-antsImageRead( getANTsRData("r64") )
mival<-invariantImageSimilarity( fi, mi, thetas = c(0,10,20) )
mapped = antsApplyTransforms( fi, mi, transformlist=mival[[2]] )
areg = antsRegistration( fi, mi, typeofTransform="Affine",
initialTransform=mival[[2]] )
bestInd = which.min( mival[[1]]$MetricValue )
txparams = as.numeric( mival[[1]][ bestInd,2:(ncol( mival[[1]] )-2) ] )
txfixedparams = as.numeric( mival[[1]][ bestInd,(ncol( mival[[1]] )-2+1):ncol( mival[[1]] )] )
affTx = createAntsrTransform( type = "AffineTransform", dimension = 2,
parameters = txparams, fixed.parameters = txfixedparams )
mapped2 = applyAntsrTransformToImage( affTx, mi, fi )
scaleMat = diag( 2 ) * 0.75
affTx = createAntsrTransform( type = "AffineTransform", dimension = 2,
matrix = scaleMat, fixed.parameters = c(125.2706, 129.2100) )
temp = applyAntsrTransformToImage( affTx, mi, mi )
mival<-invariantImageSimilarity( fi, temp, thetas = c(0,10,20),
localSearchIterations = 10, transform='Similarity' )
mapped = antsApplyTransforms( fi, temp, transformlist=mival[[2]] )
mival<-invariantImageSimilarity( fi, temp, thetas = c(0,10,20),
localSearchIterations = 10, transform='Affine' )
mapped2 = antsApplyTransforms( fi, temp, transformlist=mival[[2]] )
print( cor( fi[ fi > 0 ], temp[fi>0] ))
print( cor( fi[ fi > 0 ], mapped[fi>0] ))
print( cor( fi[ fi > 0 ], mapped2[fi>0] ))
cos45 = cos(pi*45/180)
sin45 = sin(pi*45/180)
txRotate <- createAntsrTransform( precision="float", type="AffineTransform", dim=2 )
setAntsrTransformParameters(txRotate, c(cos45,-sin45,sin45,cos45,0,0) )
setAntsrTransformFixedParameters(txRotate, c(128,128))
rotatedImage = applyAntsrTransform(txRotate, mi, mi)
mival<-invariantImageSimilarity( fi, rotatedImage, thetas = c(0,10,20,30,40,50),
localSearchIterations = 10, transform='Rigid' )
mapped2 = antsApplyTransforms( fi, rotatedImage, transformlist=mival[[2]] )
# }
Run the code above in your browser using DataLab