【医疗影像处理】dcm2niix python3 使用

dcm2niix将 dicom序列转为nifti。

dcm2nii 与dcm2niix

网址NITRC
dcm2nii是一个流行的工具,用于将扫描仪制造商使用的复杂格式(DICOM、PAR/REC)转换为许多科学工具使用的简单NIfTI格式。dcm2nii适用于所有的模式(CT、MRI、PET、SPECT)和序列类型。
注意:dcm2nii通常包含在MRIcron下载中。MRIcron有windows的版本mac os的版本。
dcm2niix最新的版本——dcm2niix

Use

from nipype.interfaces.dcm2nii import Dcm2niix
def transform(input_path, out_path, name):
    converter = Dcm2niix()
    converter.inputs.source_dir = input_path
    converter.inputs.compression = 5
    converter.inputs.out_filename = name
    converter.inputs.output_dir = out_path
    # converter.inputs.merge_imgs = True
    converter.cmdline
    converter.run()

Inputs:

https://nipype.readthedocs.io/en/latest/interfaces/generated/nipype.interfaces.dcm2nii.html

[Mandatory]
source_names: (a list of items which are a pathlike object or string
          representing an existing file)
        A set of filenames to be converted. Note that the current version
        (1.0.20180328) of dcm2niix converts any files in the directory. To
        only convert specific files they should be in an isolated directory
        argument: ``%s``, position: -1
        mutually_exclusive: source_dir
source_dir: (a pathlike object or string representing an existing
          directory)
        A directory containing dicom files to be converted
        argument: ``%s``, position: -1
        mutually_exclusive: source_names

[Optional]
out_filename: (a unicode string)
        Output filename template (%a=antenna (coil) number, %c=comments,
        %d=description, %e=echo number, %f=folder name, %i=ID of patient,
        %j=seriesInstanceUID, %k=studyInstanceUID, %m=manufacturer, %n=name
        of patient, %p=protocol, %s=series number, %t=time, %u=acquisition
        number, %v=vendor, %x=study ID; %z=sequence name)
        argument: ``-f %s``
output_dir: (a pathlike object or string representing an existing
          directory, nipype default value: .)
        Output directory
        argument: ``-o %s``
bids_format: (a boolean, nipype default value: True)
        Create a BIDS sidecar file
        argument: ``-b``
anon_bids: (a boolean)
        Anonymize BIDS
        argument: ``-ba``
        requires: bids_format
compress: ('y' or 'i' or 'n' or '3', nipype default value: y)
        Gzip compress images - [y=pigz, i=internal, n=no, 3=no,3D]
        argument: ``-z %s``
merge_imgs: (a boolean, nipype default value: False)
        merge 2D slices from same series
        argument: ``-m``
single_file: (a boolean, nipype default value: False)
        Single file mode
        argument: ``-s``
verbose: (a boolean, nipype default value: False)
        Verbose output
        argument: ``-v``
crop: (a boolean, nipype default value: False)
        Crop 3D T1 acquisitions
        argument: ``-x``
has_private: (a boolean, nipype default value: False)
        Text notes including private patient details
        argument: ``-t``
compression: (1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9)
        Gz compression level (1=fastest, 9=smallest)
        argument: ``-%d``
comment: (a unicode string)
        Comment stored as NIfTI aux_file
        argument: ``-c %s``
ignore_deriv: (a boolean)
        Ignore derived, localizer and 2D images
        argument: ``-i``
series_numbers: (a list of items which are a unicode string)
        Selectively convert by series number - can be used up to 16 times
        argument: ``-n %s...``
philips_float: (a boolean)
        Philips precise float (not display) scaling
        argument: ``-p``
to_nrrd: (a boolean)
        Export as NRRD instead of NIfTI
        argument: ``-e``
args: (a unicode string)
        Additional parameters to the command
        argument: ``%s``
environ: (a dictionary with keys which are a bytes or None or a value
          of class 'str' and with values which are a bytes or None or a
          value of class 'str', nipype default value: {})
        Environment variables

Outputs:

converted_files: (a list of items which are a pathlike object or
          string representing an existing file)
bvecs: (a list of items which are a pathlike object or string
          representing an existing file)
bvals: (a list of items which are a pathlike object or string
          representing an existing file)
bids: (a list of items which are a pathlike object or string
          representing an existing file)

参数 out_filename

当然可以自定义。

filename (
	%a=antenna (coil) name, 
	%b=basename, 
	%c=comments, 
	%d=description,
	%e=echo number, 
	%f=folder name, 
	%i=ID of patient, 
	%j=seriesInstanceUID, 
	%k=studyInstanceUID, 
	%m=manufacturer, 
	%n=name of patient, 
	%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')

shell 命令行

dcm2niix -f "%f_%p_%t_%s" -p y -z y "/home/user/DicomDir"
  • argument: -p
    philips_float: (a boolean)
    Philips precise float (not display) scaling

  • argument: -z %s
    compress: (‘y’ or ‘i’ or ‘n’ or ‘3’, nipype default value: y)
    Gzip compress images - [y=pigz, i=internal, n=no, 3=no,3D]

保存的 json文件相关条目

{
	"Modality": ,
	"MagneticFieldStrength": ,
	"ImagingFrequency": ,
	"Manufacturer": ,
	"ManufacturersModelName": ,
	"InstitutionName": ,
	"InstitutionalDepartmentName": ,
	"DeviceSerialNumber": ,
	"StationName": ,
	"BodyPartExamined": ,
	"PatientPosition": ,
	"ProcedureStepDescription": ,
	"SoftwareVersions": ,
	"MRAcquisitionType":,
	"SeriesDescription": ,
	"ProtocolName": ,
	"ScanningSequence": ,
	"SequenceVariant": ,
	"ScanOptions": ,
	"ImageType": ,
	"SeriesNumber": ,
	"AcquisitionTime": 
	"AcquisitionNumber": ,
	"PhilipsRescaleSlope": ,
	"PhilipsRescaleIntercept": ,
	"PhilipsScaleSlope": ,
	"UsePhilipsFloatNotDisplayScaling": ,
	"SliceThickness": ,
	"SpacingBetweenSlices": ,
	"SAR": ,
	"EchoTime": ,
	"RepetitionTime": ,
	"FlipAngle": ,
	"CoilString": ,
	"PercentPhaseFOV": ,
	"EchoTrainLength": ,
	"PhaseEncodingSteps": ,
	"AcquisitionMatrixPE": ,
	"ReconMatrixPE": ,
	"PixelBandwidth": ,
	"ImageOrientationPatientDICOM": ,
	"InPlanePhaseEncodingDirectionDICOM": ,
	"ConversionSoftware": "dcm2niix",
	"ConversionSoftwareVersion": "v1.0.20190902"
}

一共保存了44个条目。
包括跟扫描相关的参数,以及转换软件相关的参数。

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值