Skip to content

Commit

Permalink
Cope with deletion/anonymization of instance number (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Aug 1, 2018
1 parent cb603bb commit 8e973b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion console/nii_dicom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5271,7 +5271,7 @@ double TE = 0.0; //most recent echo time recorded
int imgBytes = (d.xyzDim[1] * d.xyzDim[2] * int(d.bitsAllocated / 8));
if (imgBytes == lLength)
isIconImageSequence = false;
if (sqDepth < 1) printWarning("Assuming 7FE0,0010 to an icon not the main image\n");
if (sqDepth < 1) printWarning("Assuming 7FE0,0010 refers to an icon not the main image\n");

}
if ((d.compressionScheme == kCompressNone ) && (!isIconImageSequence)) //do not exit for proprietary thumbnails
Expand Down
18 changes: 17 additions & 1 deletion console/nii_dicom_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3166,6 +3166,23 @@ void fillTDCMsort(struct TDCMsort& tdcmref, const uint64_t indx, const struct TD
tdcmref.img = ((uint64_t)dcmdata.seriesNum << 32) + dcmdata.imageNum;
for(int i = 0; i < MAX_NUMBER_OF_DIMENSIONS; ++i)
tdcmref.dimensionIndexValues[i] = dcmdata.dimensionIndexValues[i];
//lines below added to cope with extreme anonymization
// https://github.com/rordenlab/dcm2niix/issues/211
if (tdcmref.dimensionIndexValues[MAX_NUMBER_OF_DIMENSIONS-1] != 0) return;
//Since dimensionIndexValues are indexed from 1, 0 indicates unused
// we leverage this as a hail mary attempt to distinguish images with identical series and instance numbers
//See Correction Number CP-1242:
// "Clarify in the description of dimension indices ... start from 1"
// 0008,0032 stored as HHMMSS.FFFFFF, there are 86400000 ms per day
// dimensionIndexValues stored as uint32, so encode acquisition time in ms
uint32_t h = trunc(dcmdata.acquisitionTime / 10000.0);
double tm = dcmdata.acquisitionTime - (h * 10000.0);
uint32_t m = trunc(tm / 100.0);
tm = tm - (m * 100.0);
uint32_t ms = round(tm * 1000);
ms += (h * 3600000) + (m * 60000);
//printf("HHMMSS.FFFF %.5f -> %d ms\n", dcmdata.acquisitionTime, ms);
tdcmref.dimensionIndexValues[MAX_NUMBER_OF_DIMENSIONS-1] = ms;
} // fillTDCMsort()

int compareTDCMsort(void const *item1, void const *item2) {
Expand Down Expand Up @@ -3707,7 +3724,6 @@ int nii_loadDir(struct TDCMopts* opts) {
dcmList[j].isMultiEcho = isMultiEcho;
dcmList[i].isNonParallelSlices = isNonParallelSlices;
dcmList[j].isNonParallelSlices = isNonParallelSlices;

}
qsort(dcmSort, nConvert, sizeof(struct TDCMsort), compareTDCMsort); //sort based on series and image numbers....
//dcmList[dcmSort[0].indx].isMultiEcho = isMultiEcho;
Expand Down

0 comments on commit 8e973b9

Please sign in to comment.