questions > Extract date of scan from converted nifti files
Showing 1-5 of 5 posts
Display:
Results per page:
Jan 3, 2023  12:01 PM | Doug N
Extract date of scan from converted nifti files
Hello, 

I often receive a lot of clinical scans collected on different date on a single CD. Usually only one of these scans will be used for analysis. 

dcm2niix works very well at converting all of files on a CD into .nii and .json metadata. However, I cannot find the date of the scans anywhere in either the nifti or json files, even though the dates are in the raw DICOM images. 

Is it possible to extract the date of the scan from the nifti, or to quickly locate the DICOM images used in creating a particular nifti?

Thanks, 
Doug
Jan 3, 2023  02:01 PM | Chris Rorden
RE: Extract date of scan from converted nifti files
By default, dcm2niix will generate anonymized BIDS files. You can use `-ba n` to include private information into the BIDS JSON (e.g. "dcm2niix -ba n /path/to/DICOMs"). Another option would be to encode the date/time into the filename (e.g. "dcm2niix -f %p_%s_%t /path/to/DICOMS").

 
$ dcm2niix
Chris Rorden's dcm2niiX version v1.0.20220720 Clang12.0.5 ARM (64-bit MacOS)
usage: dcm2niix [options]
Options :
-1..-9 : gz compression level (1=fastest..9=smallest, default 6)
-a : adjacent DICOMs (images from same series always in same folder) for faster conversion (n/y, default n)
-b : BIDS sidecar (y/n/o [o=only: no NIfTI], default y)
-ba : anonymize BIDS (y/n, default y)
-c : comment stored in NIfTI aux_file (provide up to 24 characters e.g. '-c first_visit')
-d : directory search depth. Convert DICOMs in sub-folders of in_folder? (0..9, default 5)
-e : export as NRRD (y) or MGH (o) instead of NIfTI (y/n/o/j/b, default n)
-f : filename (%a=antenna (coil) name, %b=basename, %c=comments, %d=description, %e=echo number, %f=folder name, %g=accession number, %i=ID of patient, %j=seriesInstanceUID, %k=studyInstanceUID, %m=manufacturer, %n=name of patient, %o=mediaObjectInstanceUID, %p=protocol, %r=instance number, %s=series number, %t=time, %u=acquisition number, %v=vendor, %x=study ID; %z=sequence name; default '%f_%p_%t_%s')
Jan 3, 2023  04:01 PM | Doug N
RE: Extract date of scan from converted nifti files
Thanks Chris,

This is very helpful. Is there a way to only extract the date into the filename, rather than both the date and time?


Doug
Jan 3, 2023  04:01 PM | Chris Rorden
RE: Extract date of scan from converted nifti files
The software is open source. You can make a fork and adjust it as you wish:
  https://github.com/rordenlab/dcm2niix/blob/bb3a6c35d2bbac6ed95acb2cd0df65f35e79b5fb/console/nii_dicom_batch.cpp#L3140
Alternatively, you could write a Python script to adapt the filenames.
Jan 3, 2023  04:01 PM | Doug N
RE: Extract date of scan from converted nifti files
Thanks!