内容简介:翻译自:https://stackoverflow.com/questions/52757300/how-to-add-transfer-syntax-uid-to-the-filemeta-of-dataset
ds.is_little_endian = True ds.is_implicit_VR = False ds.file_meta.TransferSyntaxUID = JPEGLossless ds.is_explicit_VR = True etc
如果我不使用上面的标志,那么生成的dcm文件将无效,因为没有传输语法.
由于我不知道传输语法,我在运行程序时在命令行参数中发送传输语法,并相应地设置上述标志,并保存数据集.我知道这是错误的方法,但我只是用它作为临时解决方案.有没有更好的方法来检测传输语法,因为标签(0002,0010)缺失.
下面是我使用来自CT机器的数据集保存dcm文件的代码.现在我发送传输语法作为命令行参数
from pynetdicom3 import AE, VerificationPresentationContexts, StoragePresentationContexts, QueryRetrievePresentationContexts from pydicom.uid import ImplicitVRLittleEndian, ExplicitVRLittleEndian, JPEGLossless from pynetdicom3.sop_class import CTImageStorage, MRImageStorage from pynetdicom3 import pynetdicom_uid_prefix from pydicom.dataset import Dataset, FileDataset import argparse import uuid import os import django import logging ttt = [] ttt.extend(VerificationPresentationContexts) ttt.extend(StoragePresentationContexts) ttt.extend(QueryRetrievePresentationContexts) os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'lh_dcm_viewer.settings') django.setup() from dcm_app.models import DCMFile, DCMFileException def _setup_argparser(): parser = argparse.ArgumentParser( description="The getscp application implements a Service Class " "Provider (SCP) for the Query/Retrieve (QR) Service Class " "and the Basic Worklist Management (BWM) Service Class. " "getscp only supports query functionality using the C-GET " "message. It receives query keys from an SCU and sends a " "response. The application can be used to test SCUs of the " "QR and BWM Service Classes.", usage="getscp [options] port") # Parameters # Transfer Syntaxes ts_opts = parser.add_argument_group('Preferred Transfer Syntaxes') ts_opts.add_argument("--type", help="prefer explicit VR local byte order (default)") ts_opts.add_argument("--detect_transfer_syntax", help="Detect transfer syntax") ts_opts.add_argument("--port", help="port at which the SCP listens") return parser.parse_args() args = _setup_argparser() ae = AE(ae_title=b'MY_ECHO_SCP', port=int(args.port)) if args.type == "jpeg_lossless": ae.add_supported_context('1.2.840.10008.1.2.4.57') elif args.type == "implicit": ae.add_supported_context('1.2.840.10008.1.2') print("ImplicitVRLittleEndian") elif args.type == "explicit": ae.add_supported_context('1.2.840.10008.1.2.1') ae.requested_contexts = ttt ae.supported_contexts = ttt DICOM_IP = '192.168.1.11' DICOM_IP = '127.0.0.1' DICOM_PORT = 5678 def save_file(dataset, context, info): try: random_str = uuid.uuid4().hex meta = Dataset() meta.MediaStorageSOPClassUID = dataset.SOPClassUID meta.MediaStorageSOPInstanceUID = dataset.SOPInstanceUID meta.ImplementationClassUID = pynetdicom_uid_prefix meta.FileMetaInformationGroupLength = 202 received_file_path = "../received_dcms/%s.dcm" % random_str dataset_vr = None try: dataset_vr = dataset[("6000", "3000")].VR except KeyError: pass print(dataset_vr) if args.type == "implicit" or dataset_vr == "OB or OW": ds = FileDataset(received_file_path, {}, file_meta=meta, preamble=b"\0" * 128) ds.update(dataset) ds.is_little_endian = True ds.is_implicit_VR = True if(dataset_vr == "OB or OW"): print("forced ImplicitVRLittleEndian") ds.file_meta.TransferSyntaxUID = ImplicitVRLittleEndian elif args.type == "jpeg_lossless": ds = FileDataset(received_file_path, {}, file_meta=meta, preamble=b"\0" * 128) ds.update(dataset) ds.is_little_endian = True ds.is_implicit_VR = False ds.file_meta.TransferSyntaxUID = JPEGLossless ds.is_explicit_VR = True elif args.type == "explicit": meta.TransferSyntaxUID = "1.2.840.10008.1.2.1" ds = FileDataset(received_file_path, {}, file_meta=meta, preamble=b"\0" * 128) ds.update(dataset) ds.is_little_endian = True ds.is_implicit_VR = False ds.file_meta.TransferSyntaxUID = ExplicitVRLittleEndian ds.is_explicit_VR = True ds.save_as(received_file_path) f = open(received_file_path, "rb") f.close() return 0XC200 return status except Exception as e: logger.error(e) ae.on_c_store = save_file ae.start()
可在此处找到对此库的支持:
https://groups.google.com/forum/#!forum/pydicom代码本身在GitHub上维护,您可以在其中打开错误报告并查看所有其他错误报告: https://github.com/pydicom/pydicom/issues
翻译自:https://stackoverflow.com/questions/52757300/how-to-add-transfer-syntax-uid-to-the-filemeta-of-dataset
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 东进量子加密传输网关:为数据传输套上“金钟罩”
- 大规模数据传输,知易行难 — 数据传输与 ETL 平台的架构演进 原 荐
- 传输对象组装器模式
- 详解NFS文件传输服务
- 媒体传输的可靠性
- HTTP 响应的分块传输
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
B端产品经理必修课
李宽 / 电子工业出版社 / 2018-9 / 59
《B端产品经理必修课:从业务逻辑到产品构建全攻略》主要讲述了“单个产品管理流程”,以展示B 端产品经理的工作方法及B 端产品的设计方法。《B端产品经理必修课:从业务逻辑到产品构建全攻略》分为三个部分。第一部分主要讲述的是B 端产品经理的工作流程和定义(即单个产品管理流程),以及从事B 端产品经理的职业现状和规划,还包括设计B 端产品时需要了解的指导思想。第二部分是通过各个章节来讲述单个产品管理流程......一起来看看 《B端产品经理必修课》 这本书的介绍吧!