Skip to content

Commit

Permalink
fixing pixeltype float related to ANTsX/ANTsRCore#120
Browse files Browse the repository at this point in the history
  • Loading branch information
muschellij2 committed Jul 9, 2020
1 parent c43f92d commit 6f014cc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Imports: methods, stats, grDevices, graphics, utils, oro.nifti, ANTsR
2.17.1), WhiteStripe, matrixStats, R.matlab, abind, R.utils,
plyr, RNifti, stapler
BugReports: https://github.com/muschellij2/extrantsr/issues
RoxygenNote: 7.1.0
RoxygenNote: 7.1.1
Remotes: muschellij2/neurobase, muschellij2/fslr, bjw34032/oro.nifti,
muschellij2/kirby21.t1, ANTsX/ANTsR, ANTsX/ANTsRCore,
muschellij2/stapler
Expand Down
27 changes: 19 additions & 8 deletions R/ants_apply_transforms.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ setMethod("ants_apply_transforms",
fixed = check_ants(fixed)
moving = check_ants(moving)
if (length(moving) > 1) {
res = lapply(moving, ants_apply_transforms,
fixed = fixed, transformlist = transformlist,
... = ...)
res = lapply(moving, ants_apply_transforms,
fixed = fixed, transformlist = transformlist,
... = ...)
} else {
res = ants_apply_transforms(fixed = fixed,
moving = moving,
Expand Down Expand Up @@ -88,10 +88,21 @@ setMethod("ants_apply_transforms",
}
tclasses = sapply(transformlist, class)
stopifnot(all(tclasses %in% "character"))
moving_to_fixed = antsApplyTransforms(fixed = fixed,
moving = moving,
transformlist = transformlist,
...)
ptype = ANTsRCore::pixeltype(moving)
if (ptype %in% "unsigned char") {
warning(paste0(
"Moving had pixeltype unsigned char, cloning",
", see https://github.com/ANTsX/ANTsRCore/issues/120")
)
moving = ANTsRCore::antsImageClone(
moving,
out_pixeltype = "float")
}
moving_to_fixed = antsApplyTransforms(
fixed = fixed,
moving = moving,
transformlist = transformlist,
...)
if (!is.antsImage(moving_to_fixed)) {
warning("Output is not an antsImage object, results may be wrong")
}
Expand All @@ -103,4 +114,4 @@ setMethod("ants_apply_transforms",
gc();
}
return(moving_to_fixed)
})
})

0 comments on commit 6f014cc

Please sign in to comment.