rordenlab / dcm2niix

dcm2nii DICOM to NIfTI converter: compiled versions available from NITRC
https://www.nitrc.org/plugins/mwiki/index.php/dcm2nii:MainPage
Other
881 stars 228 forks source link

convert a single series given a dicom file #519

Closed satra closed 3 years ago

satra commented 3 years ago

Describe the bug

This is more of a feature request than a bug, unless there is a way to do this and the help doesn't help :)

i'm trying to convert a single series but this command just converts a single slice:

$ ./dcm2niix -a y -s y -o .  ../rawdata/BANDA215/MR.1.3.12.2.1107.5.2.43.67026.2020112514434014956013217
Chris Rorden's dcm2niiX version v1.0.20210317  (JP2:OpenJPEG) (JP-LS:CharLS) GCC5.5.0 x86-64 (64-bit Linux)
Convert 1 DICOM as ./BANDA215_HCP_MGH_T1w_MPR_vNav_20201125140910_9 (300x320x1x1)
Warning: Check that 2D images are not mirrored.
Conversion required 0.137606 seconds (0.110000 for core code).

in heudiconv we extract the group of files that the series belongs to and (put it in an isolated directory and then convert). but was wondering if there was a way to do that in dcm2niix itself.

Please report the complete version string:

dcm2niiX version v1.0.20210317 (JP2:OpenJPEG) (JP-LS:CharLS) GCC5.5.0 x86-64 (64-bit Linux)

neurolabusc commented 3 years ago

@satra the -s y feature limits conversion to a single file, which will work for enhanced DICOM, but not classic 2D DICOM. The way that FSLeyes and MRIcroGL solve this problem is to make two calls to dcm2niix - the first uses -n -1 identifies the CRC for the SeriesUID as a list (lines begin with a tab followed by the CRC, followed by a tab, followed by output name). Since the output name is controlled by -f, you can use this to identify particular protocols. The second call to dcm2niix provides the desired CRC, e.g. -n 4220373546 to convert just that image....

$ ./dcm2niix -n -1  ~/dcm                 
Chris Rorden's dcm2niiX version v1.0.20210531  Clang12.0.5 ARM (64-bit MacOS)
Found 432 DICOM file(s)
    1798494139  /Users/chrisrorden/dcm/dcm_Brain_Advanced_Sequences_20201014203806_2
 /Users/chrisrorden/dcm/2/0001.dcm
    4220373546  /Users/chrisrorden/dcm/dcm_Brain_Advanced_Sequences_20201014203806_3
 /Users/chrisrorden/dcm/3/0001.dcm
Conversion required 0.126730 seconds (0.083902 for core code).
$ ./dcm2niix -n 4220373546  ~/dcm

If you know the filename of the image you want to extract, you can use -s y for the first call:

$./dcm2niix -n -1 -s y  ~/dcm/3/0001.dcm   
Chris Rorden's dcm2niiX version v1.0.20210531  Clang12.0.5 ARM (64-bit MacOS)
    4220373546  /Users/chrisrorden/dcm/3/3_Brain_Advanced_Sequences_20201014203806_3
 /Users/chrisrorden/dcm/3/0001.dcm
Conversion required 0.003892 seconds (0.002540 for core code).
$ ./dcm2niix -n 4220373546  ~/src/dcm_qa  

In theory, these two calls could be combined by dcm2niix. However, for backward compatibility, I would suggest supporting the two calls to serve your purpose.

neurolabusc commented 3 years ago

Alternatively, since heudiconv already has information about the DICOMs, you could also compute the CRC32 for the DICOM SeriesInstanceUID tag (0020,000E0).

import zlib
#assuming (0020,000e) UI [1.2.840.113619.2.475.5282380.4724930.23928.1602193012.79] #  56, 1 SeriesInstanceUID
uid = b'1.2.840.113619.2.475.5282380.4724930.23928.1602193012.79'
zlib.crc32(uid)
# -> 4220373546
satra commented 3 years ago

thanks @neurolabusc