Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions nifti2/nifti_regress_test/cmake_testscripts/c22_copy_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ DATA=$2
OUT_DATA=$(dirname ${DATA}) #Need to write to separate directory
cd ${OUT_DATA}


# Compare two NIfTI files by content rather than by compressed bytes.
#
# gzip output is not reproducible across zlib implementations: zlib-ng,
# which Arch, CachyOS and other current distributions ship as the system
# zlib, encodes the same input differently from stock zlib. Comparing
# the .gz files directly therefore fails on those systems even though the
# image data round-trips perfectly. Decompress first and compare that.
nii_cmp() {
if [ "${1##*.}" = "gz" ]; then
gzip -dc "$1" > "$1.raw" && gzip -dc "$2" > "$2.raw" || return 1
cmp "$1.raw" "$2.raw"
return $?
fi
cmp "$1" "$2"
}

# note the main input file and prefix for all output files
infile=$DATA/e4.60005.nii.gz
prefix=out.c22
Expand Down Expand Up @@ -42,7 +59,7 @@ ${NT} -copy_image -infile ${prefix}.0.i16.nii.gz \
${NT} -copy_image -infile ${prefix}.1.i64.nii.gz \
-prefix ${prefix}.2.0.i16.nii.gz \
-convert2dtype NIFTI_TYPE_INT16 -convert_verify
if cmp ${prefix}.0.i16.nii.gz ${prefix}.2.0.i16.nii.gz
if nii_cmp ${prefix}.0.i16.nii.gz ${prefix}.2.0.i16.nii.gz
then
echo ""
else
Expand All @@ -57,7 +74,7 @@ ${NT} -cbl -infile ${prefix}.0.i16.nii.gz \
${NT} -copy_image -infile ${prefix}.1.f32.nii.gz \
-prefix ${prefix}.2.1.i16.nii.gz \
-convert2dtype NIFTI_TYPE_INT16 -convert_fail_choice warn
if cmp ${prefix}.0.i16.nii.gz ${prefix}.2.1.i16.nii.gz
if nii_cmp ${prefix}.0.i16.nii.gz ${prefix}.2.1.i16.nii.gz
then
echo ""
else
Expand Down
Loading