Skip to content

Commit 14fbefb

Browse files
committed
Override DICOM intensity scaling (#973)
1 parent 4f053ad commit 14fbefb

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

console/main_console.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void showHelp(const char *argv[], struct TDCMopts opts) {
7979
printf(" -m : merge 2D slices from same series regardless of echo, exposure, etc. (n/y or 0/1/2, default 2) [no, yes, auto]\n");
8080
printf(" -n : only convert this series CRC number - can be used up to %i times (default convert all)\n", MAX_NUM_SERIES);
8181
printf(" -o : output directory (omit to save to input folder)\n");
82-
printf(" -p : Philips precise float (not display) scaling (y/n, default y)\n");
82+
printf(" -p : Philips precise float (not display) scaling (y/n/o, default y; o to override and ignore variable intensity scaling)\n");
8383
printf(" -q : only search directory for DICOMs (y/l/n, default y) [y=show number of DICOMs found, l=additionally list DICOMs found, n=no]\n");
8484
printf(" -r : rename instead of convert DICOMs (y/n, default n)\n");
8585
printf(" -s : single file mode, do not convert other images in folder (y/n, default n)\n");
@@ -446,7 +446,9 @@ int main(int argc, const char *argv[]) {
446446
i++;
447447
if (invalidParam(i, argv))
448448
return 0;
449-
if ((argv[i][0] == 'n') || (argv[i][0] == 'N') || (argv[i][0] == '0'))
449+
if ((argv[i][0] == 'o') || (argv[i][0] == 'O'))
450+
opts.isIgnoreIntensityScaling = true;
451+
else if ((argv[i][0] == 'n') || (argv[i][0] == 'N') || (argv[i][0] == '0'))
450452
opts.isPhilipsFloatNotDisplayScaling = false;
451453
else
452454
opts.isPhilipsFloatNotDisplayScaling = true;

console/nii_dicom.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5326,10 +5326,8 @@ struct TDICOMdata readDICOMx(char *fname, struct TDCMprefs *prefs, struct TDTI4D
53265326
d.imageStart = (int)lPos + (int)lFileOffset;
53275327
isBasicOffsetTable = true;
53285328
}
5329-
printf("!%d %d\n", lLength, isBasicOffsetTable );
53305329
if (!isBasicOffsetTable) {
53315330
d.imageBytes = lLength;
5332-
printf("!!!!%d\n", lLength );
53335331
if (d.offsetTableItems < kMaxSlice2D)
53345332
dti4D->offsetTable[d.offsetTableItems] = (int)lPos + (int)lFileOffset;
53355333
d.offsetTableItems ++;

console/nii_dicom_batch.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,7 +2389,8 @@ tse3d: T2*/
23892389
// FSL definition is start of first line until start of last line.
23902390
// Other than the use of (n-1), the value is basically just 1.0/bandwidthPerPixelPhaseEncode.
23912391
// https://github.com/rordenlab/dcm2niix/issues/130
2392-
if (d.manufacturer != kMANUFACTURER_UIH) // issue606
2392+
// https://neurostars.org/t/error-bids-validation-after-dcm2bids-conversion-repetitiontime-and-acquisitionduration-are-mutually-exclusive/30759/13
2393+
if ((d.manufacturer != kMANUFACTURER_UIH) && (d.TR <= 0.0)) // issue606
23932394
json_Float(fp, "\t\"AcquisitionDuration\": %g,\n", d.acquisitionDuration);
23942395
if ((d.manufacturer == kMANUFACTURER_UIH) && (effectiveEchoSpacing <= 0.0)) // issue225, issue531
23952396
json_Float(fp, "\t\"TotalReadoutTime\": %g,\n", d.acquisitionDuration / 1000.0);
@@ -6669,7 +6670,6 @@ int nii_saveCrop(char *niiFilename, struct nifti_1_header hdr, unsigned char *im
66696670
hdrX.srow_y[3] += hdr.srow_y[2] * ventralCrop;
66706671
hdrX.srow_z[3] += hdr.srow_z[2] * ventralCrop;
66716672
//issue889 - also change origin for qform
6672-
//mork
66736673
mat44 Q44;
66746674
LOAD_MAT44(Q44,
66756675
hdrX.srow_x[0], hdrX.srow_x[1], hdrX.srow_x[2], hdrX.srow_x[3],
@@ -8281,6 +8281,15 @@ int saveDcm2NiiCore(int nConvert, struct TDCMsort dcmSort[], struct TDICOMdata d
82818281
#endif
82828282

82838283
struct nifti_1_header hdr0 = {0};
8284+
8285+
if ((iVaries) && (dcmList[indx].manufacturer != kMANUFACTURER_PHILIPS) && (!opts.isPhilipsFloatNotDisplayScaling)) {
8286+
printWarning("Variance of DICOM slope/intercept is being ignored due to use of the `-p n` option.\n");
8287+
iVaries = false;
8288+
}
8289+
if ((iVaries) && (opts.isIgnoreIntensityScaling)) {
8290+
printWarning("Variance of DICOM slope/intercept is being ignored due to use of the `-p o` option.\n");
8291+
iVaries = false;
8292+
}
82848293
unsigned char *img = nii_loadImgXL(nameList->str[indx], &hdr0, dcmList[indx], iVaries, opts.compressFlag, opts.isVerbose, dti4D);
82858294
if (strlen(opts.imageComments) > 0) {
82868295
for (int i = 0; i < 24; i++)
@@ -8983,13 +8992,8 @@ int saveDcm2NiiCore(int nConvert, struct TDCMsort dcmSort[], struct TDICOMdata d
89838992
imgM = removeADC(&hdr0, imgM, numADC);
89848993
if (bppVaries)
89858994
printMessage("Saving as 32-bit float (bits allocated varies).\n");
8986-
else if (iVaries) {
8987-
if (!opts.isPhilipsFloatNotDisplayScaling) {
8988-
printWarning("Variance of DICOM slope/intercept is being ignored due to use of the `-p n` option.\n");
8989-
iVaries = false;
8990-
} else
8991-
printMessage("Saving as 32-bit float (slope, intercept or bits allocated varies).\n");
8992-
}
8995+
else if (iVaries)
8996+
printMessage("Saving as 32-bit float (slope, intercept or bits allocated varies).\n");
89938997
#ifndef USING_R
89948998
// divest does not support non-NIfTI formats, and requires only one
89958999
// image per series, so skip this to avoid double-saving
@@ -10620,6 +10624,7 @@ void setDefaultOpts(struct TDCMopts *opts, const char *argv[]) { // either "setD
1062010624
opts->isIgnoreDerivedAnd2D = false;
1062110625
opts->isForceOnsetTimes = true;
1062210626
opts->isPhilipsFloatNotDisplayScaling = true;
10627+
opts->isIgnoreIntensityScaling = false;
1062310628
opts->isCrop = false;
1062410629
opts->isRotate3DAcq = true;
1062510630
opts->isGz = false;

console/nii_dicom_batch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct TDicomSeries {
7474

7575
struct TDCMopts {
7676
bool isDumpNotConvert;
77-
bool isKeepDirectionVaries, isIgnoreTriggerTimes, isTestx0021x105E, isAddNamePostFixes, isSaveNativeEndian, isOneDirAtATime, isRenameNotConvert, isSave3D, isGz, isPipedGz, isFlipY, isCreateBIDS, isSortDTIbyBVal, isAnonymizeBIDS, isOnlyBIDS, isCreateText, isForceOnsetTimes, isIgnoreDerivedAnd2D, isPhilipsFloatNotDisplayScaling, isTiltCorrect, isRGBplanar, isOnlySingleFile, isForceStackDCE, isIgnoreSeriesInstanceUID, isRotate3DAcq, isCrop, isGuessBidsFilename;
77+
bool isKeepDirectionVaries, isIgnoreTriggerTimes, isTestx0021x105E, isAddNamePostFixes, isSaveNativeEndian, isOneDirAtATime, isRenameNotConvert, isSave3D, isGz, isPipedGz, isFlipY, isCreateBIDS, isSortDTIbyBVal, isAnonymizeBIDS, isOnlyBIDS, isCreateText, isForceOnsetTimes, isIgnoreDerivedAnd2D, isPhilipsFloatNotDisplayScaling, isIgnoreIntensityScaling, isTiltCorrect, isRGBplanar, isOnlySingleFile, isForceStackDCE, isIgnoreSeriesInstanceUID, isRotate3DAcq, isCrop, isGuessBidsFilename;
7878
int saveFormat, isMaximize16BitRange, isForceStackSameSeries, nameConflictBehavior, isVerbose, isProgress, compressFlag, dirSearchDepth, onlySearchDirForDICOM, gzLevel, diffCyclingModeGE; // support for compressed data 0=none,
7979
char filename[kOptsStr], outdir[kOptsStr], indir[kOptsStr], pigzname[kOptsStr], optsname[kOptsStr], indirParent[kOptsStr], imageComments[24], bidsSubject[kOptsStr], bidsSession[kOptsStr];
8080
double seriesNumber[MAX_NUM_SERIES]; // requires double must store -1 (report but do not convert) as well as seriesUidCrc (uint32)

0 commit comments

Comments
 (0)