处理DICOM标记并执行替换——PF*系列的一部分。
pfdicom-tagSub的Python项目详细描述
Quick Overview
- pfdicom_tagSub读取/编辑/保存DICOM元信息。它可以用来匿名化DICOM头数据。
Overview
pfdicom_tagSub用json结构中传递的值替换dicom头中的一组<tag, value>对。
脚本接受一个<inputDir>,然后从这一点开始,执行一个os.walk()来提取所有的subdir。检查每个subdir中是否有dicom文件(最简单地说是通过文件扩展名映射)被传递给一个处理方法,该方法读取并替换指定的dicom标记,并将结果保存到输出树中相应的目录和文件名中。
Installation
Dependencies
以下依赖项安装在主机系统/python3 virtual env上(如果从pypi中提取,它们也将自动安装):
- pfmisc(pf*对象系列的各种杂项模块和类)
- pftree(创建文件系统层次结构的字典表示)
- pfdicom(处理底层dicom文件读取)
Command line arguments
-I|--inputDir <inputDir> Input DICOM directory to examine. By default, the first file in this directory is examined for its tag information. There is an implicit assumption that each <inputDir> contains a single DICOM series. -i|--inputFile <inputFile> An optional <inputFile> specified relative to the <inputDir>. If specified, then do not perform a directory walk, but convert only this file. -e|--extension <DICOMextension> An optional extension to filter the DICOM files of interest from the <inputDir>. [-O|--outputDir <outputDir>] The output root directory that will contain a tree structure identical to the input directory, and each "leaf" node will contain the analysis results. -F|--tagFile <JSONtagFile> Parse the tags and their "subs" from a JSON formatted <JSONtagFile>. -T|--tagStruct <JSONtagStructure> Parse the tags and their "subs" from a JSON formatted <JSONtagStucture> passed directly in the command line. -o|--outputFileStem <outputFileStem> The output file stem to store data. This should *not* have a file extension, or rather, any "." in the name are considered part of the stem and are *not* considered extensions. [--outputLeafDir <outputLeafDirFormat>] If specified, will apply the <outputLeafDirFormat> to the output directories containing data. This is useful to blanket describe final output directories with some descriptive text, such as 'anon' or 'preview'. This is a formatting spec, so --outputLeafDir 'preview-%s' where %s is the original leaf directory node, will prefix each final directory containing output with the text 'preview-' which can be useful in describing some features of the output set. [--threads <numThreads>] If specified, break the innermost analysis loop into <numThreads> threads. [-x|--man] Show full help. [-y|--synopsis] Show brief help. [--json] If specified, output a JSON dump of final return. [--followLinks] If specified, follow symbolic links. -v|--verbosity <level> Set the app verbosity level. 0: No internal output; 1: Run start / stop output notification; 2: As with level '1' but with simpleProgress bar in 'pftree'; 3: As with level '2' but with list of input dirs/files in 'pftree'; 5: As with level '3' but with explicit file logging for - read - analyze - write
Examples
通过处理特定标记执行DICOM匿名化:
pfdicom_tagSub \\ -I /var/www/html/normsmall -e dcm \\ -O /var/www/html/anon \\ --tagStruct ' { "PatientName": "anonymized", "PatientID": "%_md5|7_PatientID", "AccessionNumber": "%_md5|10_AccessionNumber", "PatientBirthDate": "%_strmsk|******01_PatientBirthDate", "ReferringPhysicianName": "ReferringPhysicianName", "PhysiciansOfRecord": "PhysiciansOfRecord", "RequestingPhysician": "RequestingPhysician", "InstitutionAddress": "InstitutionAddress", "InstitutionName": "InstitutionName" } ' --threads 0 --printElapsedTime
它只在脚本结束时输出,并记录json格式的字符串。