From e77bbbd4323cd1d2b3abfa6f922704f67b0379e5 Mon Sep 17 00:00:00 2001 From: Chris Rorden Date: Fri, 15 Jun 2018 13:33:55 -0400 Subject: [PATCH] If integer scaling is used, append " isN" to NIfTI header (https://github.com/rordenlab/dcm2niix/issues/198) --- VERSIONS.md | 1 + console/nii_dicom_batch.cpp | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/VERSIONS.md b/VERSIONS.md index 2df421f1..b5de7182 100644 --- a/VERSIONS.md +++ b/VERSIONS.md @@ -8,6 +8,7 @@ - Support for Philips Private RLE (1.3.46.670589.33.1.4.1) transfer syntax. - Optional support for JPEG-LS (1.2.840.10008.1.2.4.80/1.2.840.10008.1.2.4.81) transfer syntaxes (using [CharLS](https://github.com/team-charls/charls)). Requires c++14. - [Improved GE support](https://github.com/rordenlab/dcm2niix/issues/163) + - Optional [lossless integer scaling](https://github.com/rordenlab/dcm2niix/issues/198) for INT16 and UINT16 DICOM images that only use a fraction of the possible range. 15-Dec-2017 - Support [Siemens XA10 images](https://github.com/rordenlab/dcm2niix/pull/145). diff --git a/console/nii_dicom_batch.cpp b/console/nii_dicom_batch.cpp index dfa3e073..231efddb 100644 --- a/console/nii_dicom_batch.cpp +++ b/console/nii_dicom_batch.cpp @@ -2165,6 +2165,13 @@ void nii_scale16bitSigned(unsigned char *img, struct nifti_1_header *hdr){ printMessage("Maximizing 16-bit range: raw %d..%d\n", min16, max16); }*/ +void nii_storeIntegerScaleFactor(int scale, struct nifti_1_header *hdr) { +//appends NIfTI header description field with " isN" where N is integer scaling + char newstr[256]; + sprintf(newstr, " is%d", scale); + if ((strlen(newstr)+strlen(hdr->descrip)) < 80) + strcat (hdr->descrip,newstr); +} void nii_scale16bitSigned(unsigned char *img, struct nifti_1_header *hdr) { //lossless scaling of INT16 data: e.g. input with range -100...3200 and scl_slope=1 // will be stored as -1000...32000 with scl_slope 0.1 @@ -2191,7 +2198,8 @@ void nii_scale16bitSigned(unsigned char *img, struct nifti_1_header *hdr) { hdr->scl_slope = hdr->scl_slope/ scale; for (int i=0; i < nVox; i++) img16[i] = img16[i] * scale; - printMessage("Maximizing 16-bit range: raw %d..%d\n", min16, max16); + printMessage("Maximizing 16-bit range: raw %d..%d is%d\n", min16, max16, scale); + nii_storeIntegerScaleFactor(scale, hdr); } @@ -2215,7 +2223,8 @@ void nii_scale16bitUnsigned(unsigned char *img, struct nifti_1_header *hdr){ hdr->scl_slope = hdr->scl_slope/ scale; for (int i=0; i < nVox; i++) img16[i] = img16[i] * scale; - printMessage("Maximizing 16-bit range: raw max %d\n", max16); + printMessage("Maximizing 16-bit range: raw max %d is%d\n", max16, scale); + nii_storeIntegerScaleFactor(scale, hdr); } void nii_check16bitUnsigned(unsigned char *img, struct nifti_1_header *hdr){