@@ -3439,6 +3439,22 @@ bool intensityScaleVaries(int nConvert, struct TDCMsort dcmSort[], struct TDICOM
34393439 return false ;
34403440} // intensityScaleVaries()
34413441
3442+ bool bitDepthVaries (int nConvert, struct TDCMsort dcmSort[], struct TDICOMdata dcmList[]) {
3443+ // detect whether some DICOM images report different intensity scaling
3444+ // some Siemens PET scanners generate 16-bit images where slice has its own scaling factor.
3445+ // since NIfTI provides a single scaling factor for each file, these images require special consideration
3446+ if (nConvert < 2 )
3447+ return false ;
3448+ int dt = dcmList[dcmSort[0 ].indx ].bitsAllocated ;
3449+ for (int i = 1 ; i < nConvert; i++) { // stack additional images
3450+ uint64_t indx = dcmSort[i].indx ;
3451+ if (dcmList[indx].bitsAllocated != dt)
3452+ return true ;
3453+ }
3454+ return false ;
3455+ } // bitDepthVaries()
3456+
3457+
34423458/* unsigned char * nii_bgr2rgb(unsigned char* bImg, struct nifti_1_header *hdr) {
34433459 //DICOM planarappears to be BBB..B,GGG..G,RRR..R, NIfTI RGB saved in planes RRR..RGGG..GBBBB..B
34443460 // see http://www.barre.nom.fr/medical/samples/index.html US-RGB-8-epicard
@@ -8191,6 +8207,9 @@ int saveDcm2NiiCore(int nConvert, struct TDCMsort dcmSort[], struct TDICOMdata d
81918207#endif
81928208
81938209 bool iVaries = intensityScaleVaries (nConvert, dcmSort, dcmList);
8210+ bool bppVaries = false ;
8211+ if (iVaries)
8212+ bppVaries = bitDepthVaries (nConvert, dcmSort, dcmList);
81948213 float *sliceMMarray = NULL ; // only used if slices are not equidistant
81958214 uint64_t indx = dcmSort[0 ].indx ;
81968215 uint64_t indx0 = dcmSort[0 ].indx ;
@@ -8962,8 +8981,15 @@ int saveDcm2NiiCore(int nConvert, struct TDCMsort dcmSort[], struct TDICOMdata d
89628981 }
89638982#endif // myNoRois
89648983 imgM = removeADC (&hdr0, imgM, numADC);
8965- if (iVaries)
8966- printMessage (" Saving as 32-bit float (slope, intercept or bits allocated varies).\n " );
8984+ if (bppVaries)
8985+ 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+ }
89678993#ifndef USING_R
89688994 // divest does not support non-NIfTI formats, and requires only one
89698995 // image per series, so skip this to avoid double-saving
0 commit comments