Skip to content

Commit

Permalink
WIP: remove imageMath
Browse files Browse the repository at this point in the history
  • Loading branch information
stnava committed Jun 9, 2015
1 parent f62d7a4 commit 3713fd8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 26 deletions.
6 changes: 2 additions & 4 deletions R/basicInPaint.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,16 @@ basicInPaint <- function(img, paintMask, speedimage = NA, its = 0, gparam = 0.05
temp <- antsImageClone(paintMask)
temp[temp == 1] <- 0
temp[temp == 2] <- 1
imageMath(img@dimension, temp, "MD", temp, 1)
temp = iMath(temp,"MD",1)
paintMaskUse[temp == 1 & paintMaskUse == 1] <- 2
# imageMath(img@dimension,paintMaskUse,'GD',paintMask,1)
healthymask <- antsImageClone(paintMaskUse)
healthymask[paintMaskUse == 2] <- 0
if (is.na(speedimage)) {
speedimage <- antsImageClone(img)
upit <- mean(img[paintMaskUse == 2])
speedimage[paintMaskUse == 2] <- speedimage[paintMaskUse == 2] + upit
}
imageMath(inpainted@dimension, inpainted, "FastMarchingExtension", speedimage,
healthymask, img)
inpainted = iMath( speedimage,"FastMarchingExtension", healthymask, img )
outimg <- antsImageClone(img)
outimg[paintMaskUse == 2] <- inpainted[paintMaskUse == 2]
if (its > 0) {
Expand Down
13 changes: 1 addition & 12 deletions R/compcor.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#' @param ncompcor n compcor vectors
#' @param variance_extreme high variance threshold e.g 0.95 for 95 percent
#' @param mask optional mask for image
#' @param useimagemath use the imagemath implementation instead
#' @param randomSamples take this many random samples to speed things up
#' @param returnv return the spatial vectors
#' @param returnhighvarmat bool to return the high variance matrix
Expand All @@ -20,24 +19,14 @@
#' @export compcor
compcor <- function(fmri, ncompcor = 4,
variance_extreme = 0.975,
mask = NA,
useimagemath = FALSE, randomSamples = 1,
mask = NA, randomSamples = 1,
returnv = FALSE, returnhighvarmat = FALSE,
returnhighvarmatinds = FALSE,
highvarmatinds = NA) {
if (nargs() == 0) {
print("Usage: compcorr_df<-compcor( fmri, mask ) ")
return(1)
}
if (useimagemath & !is.na(mask)) {
myoutfn <- tempfile(pattern = "file", tmpdir = tempdir(), fileext = ".nii.gz")
imageMath(4, myoutfn, "CompCorrAuto", fmri, mask, ncompcor)
mycsv <- sub(".nii.gz", "_compcorr.csv", myoutfn)
myvarimg <- sub(".nii.gz", "_variance.nii.gz", myoutfn)
varimage <- antsImageRead(myvarimg, 3)
mycompcorrdf <- read.csv(mycsv)
return(mycompcorrdf)
}
if (class(fmri)[1] == "antsImage" & is.na(mask)) {
print("Need to input a mask too")
print(args(compcor))
Expand Down
4 changes: 1 addition & 3 deletions R/getCentroids.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ getCentroids <- function(img, clustparam = 250, outprefix = NA) {
if (is.na(outprefix)) {
outprefix <- paste(tempdir(), "/Z", sep = "")
}
pointfile <- paste(outprefix, "coords.csv", sep = "")
imageMath(imagedim, pointfile, "LabelStats", img, img, clustparam)
mypoints <- read.csv(pointfile)
mypoints <- labelStats( img, img, clustparam )
centroids <- as.matrix(data.frame(x = mypoints$x, y = mypoints$y, z = mypoints$z, t=mypoints$t ))
return( centroids )
}
11 changes: 7 additions & 4 deletions R/getTemplateCoordinates.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,13 @@ getTemplateCoordinates <- function(
milab <- imagePairToBeLabeled[[2]]
mywarpedLimage <- antsApplyTransforms(fixed = fi, moving = milab, transformlist = mytx$fwdtransforms,
interpolator = c("NearestNeighbor"))
pointfile <- paste(outprefix, "coords.csv", sep = "")
imageMath(milab@dimension, pointfile, "LabelStats",
mywarpedLimage, mywarpedLimage, 1)
mypoints <- read.csv(pointfile)
mypoints <- labelStats( mywarpedLimage, mywarpedLimage )
mypoints = data.frame(
x = mypoints$x
y = mypoints$y
z = mypoints$z
t = mypoints$t
)
for (mylab in 2:length(templatePairWithLabels)) {
filab <- templatePairWithLabels[[mylab]]
if (class(filab)[[1]] != "antsImage") {
Expand Down
2 changes: 0 additions & 2 deletions R/pairwiseImageDistanceMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ pairwiseImageDistanceMatrix <- function(dim,
mytx <- antsRegistration(fixed = i1, moving = i2, typeofTransform = c("AffineFast"),
outprefix = toutfn)
mywarpedimage <- antsApplyTransforms(fixed = i1, moving = i2, transformlist = mytx$fwdtransforms)
# broken !! metric <- capture.output(imageMath(dim, 'j', metrictype, i1,
# mywarpedimage))[1]
wh <- (mywarpedimage > 0 & i1 > 0)
if (metrictype == "PearsonCorrelation") {
metric <- abs(cor.test(i1[wh], mywarpedimage[wh])$est)
Expand Down
2 changes: 1 addition & 1 deletion R/projectImageAlongAxis.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ projectImageAlongAxis <- function(imageND,
if (axis >= imageND@dimension)
axis <- (imageND@dimension - 1)
downimg <- antsImageClone(referenceImageNDminus1)
imageMath(imageND@dimension, downimg, "Project", imageND, axis, projtype)
downimg = iMath(imageND,"Project",axis,projtype)
return(downimg)
}

0 comments on commit 3713fd8

Please sign in to comment.