From 6f014cc860a28d1dae33b78c8d79257791591b7b Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Thu, 9 Jul 2020 16:01:16 -0400 Subject: [PATCH] fixing pixeltype float related to https://github.com/ANTsX/ANTsRCore/issues/120 --- DESCRIPTION | 2 +- R/ants_apply_transforms.R | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b431935..9a12f8d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 diff --git a/R/ants_apply_transforms.R b/R/ants_apply_transforms.R index 1fb648a..1f74fea 100644 --- a/R/ants_apply_transforms.R +++ b/R/ants_apply_transforms.R @@ -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, @@ -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") } @@ -103,4 +114,4 @@ setMethod("ants_apply_transforms", gc(); } return(moving_to_fixed) -}) + })