From 029275f9048a28afc52ae78d199301967396d7a1 Mon Sep 17 00:00:00 2001 From: Robert Reid Date: Fri, 22 Dec 2023 13:45:11 -0600 Subject: [PATCH 1/3] issue 769: relax the check for bvec components > 1 a bit. --- console/nii_dicom.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/console/nii_dicom.cpp b/console/nii_dicom.cpp index f6a1387d..5d2158b7 100644 --- a/console/nii_dicom.cpp +++ b/console/nii_dicom.cpp @@ -4040,7 +4040,13 @@ void _update_tvd(struct TVolumeDiffusion *ptvd) { return; //no B=0 if (isReady) { for (int i = 1; i < 4; ++i) { - if (ptvd->_dtiV[i] > 1) { + // Check that _dtiV is not still at its default of [-1, 2, 2, 2] from + // clear_volume(struct TVolumeDiffusion *ptvd). This is mostly avoided + // because of the ptvd->_dtiV[0] >= 0 check above, but was supposedly + // needed at some point. + // issue 769: some bvec components may be slightly (~5%) > 1. AFAIK, + // the relevant value to guard against would be +2. + if (ptvd->_dtiV[i] > 1.5) { isReady = false; break; } From 70abd5e2fab1ab9765592162da2d0ac5fc0f16aa Mon Sep 17 00:00:00 2001 From: Robert Reid Date: Thu, 18 Apr 2024 15:57:28 -0500 Subject: [PATCH 2/3] Disable XA partial vol detection for single slice files (rordenlab#742) --- console/nii_dicom.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/console/nii_dicom.cpp b/console/nii_dicom.cpp index f42f5fd1..522e75f8 100644 --- a/console/nii_dicom.cpp +++ b/console/nii_dicom.cpp @@ -8041,7 +8041,19 @@ const uint32_t kEffectiveTE = 0x0018 + uint32_t(0x9082 << 16); //FD //} if (numberOfFramesICEdims < 2) //issue751: icedims[20] frames for EPI only numberOfFramesICEdims = 0; - if ((numberOfFramesICEdims > 0) && (d.xyzDim[3] != numberOfFramesICEdims)) { + // Issue 742: Detect *currently* enhanced Siemens XA volumes with fewer + // than the expected number of slices, and mark them as derived, with + // SeriesNumber + 1000. However, valid XA series are often unenhanced, + // likely post-scanner, and can arrive as files with just 1 slice each + // in d.xyzDim[3] but the total number of z locations for the series in + // their ICEdims, so they appear to be partial volumes until the + // dcmList is completed (nii_dicom_batch.cpp). Thus we use the + // heuristic that d.xyzDim[3] == 1 is probably OK but between 1 and + // numberOfFramesICEdims (exclusively) is an enhanced partial + // volume. It would miss the case of a true enhanced partial volume + // with just 1 slice, but that seems much less likely than unenhanced + // DICOM with unmodified ICEDims tags. + if ((numberOfFramesICEdims > 0) && (d.xyzDim[3] > 1) && (d.xyzDim[3] != numberOfFramesICEdims)) { printWarning("Series %ld includes partial volume (issue 742): %d slices acquired but ICE dims (0021,118e) specifies %d \n", d.seriesNum, d.xyzDim[3], numberOfFramesICEdims); d.seriesNum += 1000; d.isDerived = true; From d53a237d5078bd35150a33ccaa3f25ad6cf34775 Mon Sep 17 00:00:00 2001 From: Robert Reid Date: Sat, 20 Apr 2024 15:13:26 -0500 Subject: [PATCH 3/3] Fix CSA n_tags check (#633) --- console/nii_dicom.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/console/nii_dicom.cpp b/console/nii_dicom.cpp index 522e75f8..45dcc5c7 100644 --- a/console/nii_dicom.cpp +++ b/console/nii_dicom.cpp @@ -1446,6 +1446,10 @@ int readCSAImageHeader(unsigned char *buff, int lLength, struct TCSAdata *CSA, i return EXIT_FAILURE; int lPos = 8; //skip 8 bytes of data, 'SV10' plus 2 32-bit values unused1 and unused2 int lnTag = buff[lPos] + (buff[lPos + 1] << 8) + (buff[lPos + 2] << 16) + (buff[lPos + 3] << 24); + if ((lnTag > 128) || (lnTag < 1)){ + printError("%d n_tags CSA Image Header corrupted (0029,1010) see issue 633.\n", lnTag); + return EXIT_FAILURE; + } if (buff[lPos + 4] != 77) return EXIT_FAILURE; lPos += 8; //skip 8 bytes of data, 32-bit lnTag plus 77 00 00 0 @@ -1459,10 +1463,6 @@ int readCSAImageHeader(unsigned char *buff, int lLength, struct TCSAdata *CSA, i // Storage order is always little-endian, so byte-swap required values if necessary if (!littleEndianPlatform()) nifti_swap_4bytes(1, &tagCSA.nitems); - if (tagCSA.nitems > 128) { - printError("%d n_tags CSA Image Header corrupted (0029,1010) see issue 633.\n", tagCSA.nitems); - return EXIT_FAILURE; - } if (isVerbose > 1) //extreme verbosity: show every CSA tag printMessage(" %d CSA of %s %d\n", lPos, tagCSA.name, tagCSA.nitems); if (tagCSA.nitems > 0) {