Skip to content

Commit

Permalink
New "-z 3" for uncompressed 3D volumes (old SPM)
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Aug 23, 2017
1 parent 510648c commit 6b9c921
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ This requires a compiler that supports c++11.
- [Dcm2Bids](https://github.com/cbedetti/Dcm2Bids) uses dcm2niix to create [BIDS](http://bids.neuroimaging.io/) datasets.
- [heudiconv](https://github.com/nipy/heudiconv) can use dcm2niix to create [BIDS](http://bids.neuroimaging.io/) datasets.
- [nipype](https://github.com/nipy/nipype) can use dcm2niix to convert images.
- [pydcm2niix is a Python module for working with dcm2niix](https://github.com/jstutters/pydcm2niix).
- [dcm2niir](https://github.com/muschellij2/dcm2niir) R wrapper for dcm2niix/dcm2nii.
- [divest](https://github.com/jonclayden/divest) R interface to dcm2niix.
- [sci-tran dcm2niix](https://github.com/scitran-apps/dcm2niix) docker.
Expand Down
16 changes: 10 additions & 6 deletions console/main_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ void showHelp(const char * argv[], struct TDCMopts opts) {
if (opts.isGz) gzCh = 'y';
#ifdef myDisableZLib
if (strlen(opts.pigzname) > 0)
printf(" -z : gz compress images (y/n, default %c)\n", gzCh);
printf(" -z : gz compress images (y/n/3, default %c) [y=pigz, n=no, 3=no,3D]\n", gzCh);
else
printf(" -z : gz compress images (y/n, default %c) [REQUIRES pigz]\n", gzCh);
printf(" -z : gz compress images (y/n/3, default %c) [y=pigz(MISSING!), n=no, 3=no,3D]\n", gzCh);
#else
#ifdef myDisableMiniZ
printf(" -z : gz compress images (y/i/n, default %c) [y=pigz, i=internal:zlib, n=no]\n", gzCh);
printf(" -z : gz compress images (y/i/n/3, default %c) [y=pigz, i=internal:zlib, n=no, 3=no,3D]\n", gzCh);
#else
printf(" -z : gz compress images (y/i/n, default %c) [y=pigz, i=internal, n=no]\n", gzCh);
printf(" -z : gz compress images (y/i/n/3, default %c) [y=pigz, i=internal, n=no, 3=no,3D]\n", gzCh);
#endif
#endif

Expand Down Expand Up @@ -133,7 +133,8 @@ int invalidParam(int i, const char * argv[]) {
|| (argv[i][0] == 'o') || (argv[i][0] == 'O')
|| (argv[i][0] == 'h') || (argv[i][0] == 'H')
|| (argv[i][0] == 'i') || (argv[i][0] == 'I')
|| (argv[i][0] == '0') || (argv[i][0] == '1') || (argv[i][0] == '2'))
|| (argv[i][0] == '0') || (argv[i][0] == '1')
|| (argv[i][0] == '2') || (argv[i][0] == '3') )
return 0;

//if (argv[i][0] != '-') return 0;
Expand Down Expand Up @@ -256,7 +257,10 @@ int main(int argc, const char * argv[])
} else if ((argv[i][1] == 'z') && ((i+1) < argc)) {
i++;
if (invalidParam(i, argv)) return 0;
if ((argv[i][0] == 'i') || (argv[i][0] == 'I') ) {
if ((argv[i][0] == '3') ) {
opts.isGz = false; //uncompressed 3D
opts.isSave3D = true;
} else if ((argv[i][0] == 'i') || (argv[i][0] == 'I') ) {
opts.isGz = true; //force use of internal compression instead of pigz
strcpy(opts.pigzname,"");
} else if ((argv[i][0] == 'n') || (argv[i][0] == 'N') || (argv[i][0] == '0'))
Expand Down
20 changes: 16 additions & 4 deletions console/nii_dicom_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,10 @@ unsigned long mz_crc32(unsigned long crc, const unsigned char *ptr, size_t buf_l
#define MZ_UBER_COMPRESSION 9
#endif

#ifndef MZ_DEFAULT_LEVEL
#define MZ_DEFAULT_LEVEL 6
#endif

void writeNiiGz (char * baseName, struct nifti_1_header hdr, unsigned char* src_buffer, unsigned long src_len, int gzLevel) {
//create gz file in RAM, save to disk http://www.zlib.net/zlib_how.html
// in general this single-threaded approach is slower than PIGZ but is useful for slow (network attached) disk drives
Expand All @@ -1359,7 +1363,7 @@ void writeNiiGz (char * baseName, struct nifti_1_header hdr, unsigned char* src
strm.opaque = Z_NULL;
strm.next_out = pCmp; // output char array
strm.avail_out = (unsigned int)cmp_len; // size of output
int zLevel = Z_DEFAULT_COMPRESSION;
int zLevel = MZ_DEFAULT_LEVEL;//Z_DEFAULT_COMPRESSION;
if ((gzLevel > 0) && (gzLevel < 11))
zLevel = gzLevel;
if (zLevel > MZ_UBER_COMPRESSION)
Expand Down Expand Up @@ -2184,12 +2188,18 @@ int saveDcm2Nii(int nConvert, struct TDCMsort dcmSort[],struct TDICOMdata dcmLis
char pathoutnameADC[2048] = {""};
strcat(pathoutnameADC,pathoutname);
strcat(pathoutnameADC,"_ADC");
nii_saveNII(pathoutnameADC, hdr0, imgM, opts);
if (opts.isSave3D)
nii_saveNII3D(pathoutnameADC, hdr0, imgM, opts);
else
nii_saveNII(pathoutnameADC, hdr0, imgM, opts);
}
#endif
imgM = removeADC(&hdr0, imgM, numADC);
#ifndef HAVE_R
returnCode = nii_saveNII(pathoutname, hdr0, imgM, opts);
if (opts.isSave3D)
returnCode = nii_saveNII3D(pathoutname, hdr0, imgM, opts);
else
returnCode = nii_saveNII(pathoutname, hdr0, imgM, opts);
#endif
}
#endif
Expand Down Expand Up @@ -2821,7 +2831,9 @@ void setDefaultOpts (struct TDCMopts *opts, const char * argv[]) { //either "set
opts->isPhilipsFloatNotDisplayScaling = true;
opts->isCrop = false;
opts->isGz = false;
opts->gzLevel = -1;
opts->isSave3D = false;
opts->gzLevel = MZ_DEFAULT_LEVEL; //-1;
printMessage(">>>>> %d\n",Z_DEFAULT_COMPRESSION);
opts->isFlipY = true; //false: images in raw DICOM orientation, true: image rows flipped to cartesian coordinates
opts->isRGBplanar = false; //false for NIfTI (RGBRGB...), true for Analyze (RRR..RGGG..GBBB..B)
opts->isCreateBIDS = true;
Expand Down
2 changes: 1 addition & 1 deletion console/nii_dicom_batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern "C" {
#endif

struct TDCMopts {
bool isGz, isFlipY, isCreateBIDS, isSortDTIbyBVal, isAnonymizeBIDS, isOnlyBIDS, isCreateText, isIgnoreDerivedAnd2D, isPhilipsFloatNotDisplayScaling, isTiltCorrect, isRGBplanar, isOnlySingleFile, isForceStackSameSeries, isCrop;
bool isSave3D,isGz, isFlipY, isCreateBIDS, isSortDTIbyBVal, isAnonymizeBIDS, isOnlyBIDS, isCreateText, isIgnoreDerivedAnd2D, isPhilipsFloatNotDisplayScaling, isTiltCorrect, isRGBplanar, isOnlySingleFile, isForceStackSameSeries, isCrop;
int isVerbose, compressFlag, gzLevel; //support for compressed data 0=none,
char filename[512], outdir[512], indir[512], pigzname[512], optsname[512], indirParent[512];
#ifdef HAVE_R
Expand Down

0 comments on commit 6b9c921

Please sign in to comment.