From f09342218bed5255a6745d945bcfc07516622f1b Mon Sep 17 00:00:00 2001 From: Ali Khan Date: Thu, 9 Jul 2026 12:38:39 -0400 Subject: [PATCH] fix for casting on a clean history --- run.sh | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/run.sh b/run.sh index 09da816..a4eaaaf 100755 --- a/run.sh +++ b/run.sh @@ -364,15 +364,26 @@ do cp -v $out_nointcorr $out_unwarped fi - echo "settings datatype to short and resetting header from original image" - #ensure final unwarped (out_unwarped) is same datatype and geom as input (assuming mr images are input type short) - echo fslmaths $out_unwarped $out_unwarped -odt short - fslmaths $out_unwarped $out_unwarped -odt short + echo "settings datatype to match input and resetting header from original image" + + #ensure final unwarped (out_unwarped) is same datatype and geom as input + #detect the original datatype so we correctly handle both signed (INT16) and unsigned (UINT16) short + orig_dtype=$(fslinfo $nii | grep "^data_type" | awk '{print $2}') + case "$orig_dtype" in + UINT8) odt="char" ;; + INT16) odt="short" ;; + UINT16) odt="int" ;; # fslmaths has no ushort; INT32 holds all UINT16 values without sign corruption + INT32) odt="int" ;; + FLOAT32) odt="float" ;; + FLOAT64) odt="double" ;; + *) odt="short" ;; + esac + echo fslmaths $out_unwarped $out_unwarped -odt $odt + fslmaths $out_unwarped $out_unwarped -odt $odt echo fslcpgeom $nii $out_unwarped fslcpgeom $nii $out_unwarped - #copy extra files for ext in json bvec bval tsv do