Пример #1
0
    def __init__(self, file_name, IsCreate=False):
        ## This code block was taken from the output of a MATLAB secondary
        ## capture.  I do not know what the long dotted UIDs mean, but
        ## this code works.
        # Define items as (VR, VM, description, is_retired flag, keyword)
        #   Leave is_retired flag blank.

        # Update the dictionary itself
        DicomDictionary.update(self.AI_ANLAYSIS_ITEM)

        if IsCreate:
            self.__file_name__ = file_name
            file_meta = Dataset()

            # Ultrasound Multiframe Image Storage - https://www.dicomlibrary.com/dicom/sop/
            file_meta.MediaStorageSOPClassUID = '1.2.840.10008.5.1.4.1.1.3.1'
            file_meta.MediaStorageSOPInstanceUID = '999.999.2.19941105.134500.2.101'
            file_meta.ImplementationClassUID = '999.999'
            # Transfer Syntax - https://www.dicomlibrary.com/dicom/transfer-syntax/
            file_meta.TransferSyntaxUID = '1.2.840.10008.1.2'

            ds = FileDataset(file_name, {},
                             file_meta=file_meta,
                             preamble=b"\0" * 128)
            # DICOM modality, that represents DICOM file type - https://www.dicomlibrary.com/dicom/modality/
            ds.Modality = 'US'  # Ultrasound
            ds.ContentDate = str(datetime.date.today()).replace('-', '')
            ds.ContentTime = str(time.time())  # milliseconds since the epoch
            ds.StudyInstanceUID = '999.999.2.19941105.134500'
            ds.SeriesInstanceUID = '999.999.2.19941105.134500.2'
            ds.SOPInstanceUID = '999.999.2.19941105.134500.2.101'

            # https://searchcode.com/codesearch/view/13929148/
            ds.SOPClassUID = '1.2.840.10008.5.1.4.1.1.3.1'  # 'Ultrasound Multi-frame Image Storage' - 1.2.840.10008.5.1.4.1.1.3.1
            # ds.SecondaryCaptureDeviceManufctur = 'Python 2.7.3'
            self.Dataset = ds
        else:
            self.Dataset = dicom.read_file(file_name)
Пример #2
0
Add dictionary items in the standard DICOM dictionary
본 예제는 DICOM 표준 Dictionary에 어떻게 동적으로 Python Dictionary를 추가하는지 보여준다.
"""

from __future__ import print_function

from pydicom.datadict import DicomDictionary, keyword_dict
from pydicom.dataset import Dataset

print(__doc__)

new_dict_items = {
    0x10011001: ('UL', '1', 'Test One', '', 'TestOne'),
    0x10011002: ('OB', '1', 'Test Two', '', 'TestTwo'),
    0x10011003: ('UI', '1', 'Test Three', '', 'TestThree')
}

DicomDictionary.update(new_dict_items)

new_names_dict = dict([(val[4], tag) for tag, val in new_dict_items.items()])
print(new_names_dict)
keyword_dict.update(new_names_dict)

ds = Dataset()

ds.TestOne = 42
ds.TestTwo = '12345'
ds.TestThree = '1.2.3.4.5'

print(ds.top())
Пример #3
0
""" Add DICOM Attributes not yet part of DICOM

    This is from CP-1570, and should be removed once the CP becomes part of
    the main standard. Note that tags may differ.
"""
from pydicom.datadict import DicomDictionary, keyword_dict

# Define items as (VR, VM, description, is_retired flag, keyword)
#   Leave is_retired flag blank.
dental_acquisition_context = {
    0x10011001: ('SQ', '1', "Acquisition View", '', 'AcquisitionView'),
    0x10011002: ('SQ', '1', "Image View", '', 'ImageView'),
    0x10011003: ('SQ', '1', "Functional condition present during"
                 "acquisition", '', 'FunctionalCondition'),
    0x10011004:
    ('SQ', '1', "Occlusal Relationship", '', 'OcclusalRelationship'),
}

# Update the dictionary itself
DicomDictionary.update(dental_acquisition_context)

# Update the reverse mapping from name to tag
keyword_dict.update(
    dict([(val[4], tag) for tag, val in dental_acquisition_context.items()]))
Пример #4
0
from pydicom.datadict import DicomDictionary, keyword_dict
from pydicom.dataset import Dataset

print(__doc__)

# Define items as (VR, VM, description, is_retired flag, keyword)
#   Leave is_retired flag blank.
new_dict_items = {
    0x10011001: ('UL', '1', "Test One", '', 'TestOne'),
    0x10011002: ('OB', '1', "Test Two", '', 'TestTwo'),
    0x10011003: ('UI', '1', "Test Three", '', 'TestThree'),
}

# Update the dictionary itself
DicomDictionary.update(new_dict_items)

# Update the reverse mapping from name to tag
new_names_dict = dict([(val[4], tag) for tag, val in
                       new_dict_items.items()])
keyword_dict.update(new_names_dict)

# Test that it is working
ds = Dataset()  # or could get one from dcmread, etc

ds.TestOne = 42
ds.TestTwo = '12345'
ds.TestThree = '1.2.3.4.5'

print(ds.top())
def table_dicom_data(dicom_tree):
    if VERBOSE > 1:
        print_this(currLog,
                   st.RESET_ALL + fg.GREEN + '* VISITING' + st.RESET_ALL)

    new_dict_items = {
        0x0021105e:
        ('DS', '1', "FloatSlopRTIATimer", '', 'FloatSlopRTIATimer'),
        0x00181060: ('DS', '1', "TriggerTime", '', 'TriggerTime'),
    }
    DicomDictionary.update(new_dict_items)
    new_names_dict = dict([(val[4], tag)
                           for tag, val in new_dict_items.items()])
    keyword_dict.update(new_names_dict)

    props = [
        'Path',
        'NumFiles',
        'StudyID',
        'StudyDate',
        'StudyTime',
        'PatientID',
        'PatientName',
        'ProtocolName',
        'SeriesDescription',
        'SeriesNumber',
        'SeriesTime',
        'ImagesInAcquisition',
        'InStackPositionNumber',
        'InstanceNumber',
        'SliceLocation',
        'TriggerTime',
        'FloatSlopRTIATimer',
    ]

    db = OrderedDict([(ii, []) for ii in props])
    if isinstance(dicom_tree, dict):
        for dicom in dicom_tree:
            if isinstance(dicom_tree[dicom], dict):
                for patient in dicom_tree[dicom]:
                    if isinstance(dicom_tree[dicom][patient], dict):
                        for exam in dicom_tree[dicom][patient]:
                            if isinstance(dicom_tree[dicom][patient][exam],
                                          dict):
                                for serie in dicom_tree[dicom][patient][exam]:
                                    if isinstance(
                                            dicom_tree[dicom][patient][exam]
                                        [serie], dict):
                                        for fn in dicom_tree[dicom][patient][
                                                exam][serie]:
                                            if VERBOSE > 1:
                                                print_this(
                                                    currLog, fg.CYAN + '  ' +
                                                    fn + st.RESET_ALL)

                                            ds = pydicom.dcmread(
                                                fn, stop_before_pixels=True)
                                            ds.decode()
                                            for prop in props:
                                                if prop == 'Path':
                                                    db[prop] += [
                                                        os.path.dirname(fn)
                                                    ]
                                                elif prop == 'NumFiles':
                                                    db[prop] += [
                                                        len(
                                                            glob.glob(
                                                                os.path.
                                                                dirname(fn) +
                                                                '/*'))
                                                    ]
                                                else:
                                                    db[prop] += [
                                                        ''
                                                    ] if not hasattr(
                                                        ds, prop) else [
                                                            getattr(ds, prop)
                                                        ]

                                            if False:
                                                print_this(currLog, str(db))
                                            if False:
                                                print_this(currLog, str(ds))

    df = pd.DataFrame(db)
    df = df.sort_values(by=['StudyID', 'SeriesNumber', 'InstanceNumber'],
                        axis=0)
    if not args.include_stacked_screen_saves:
        df = df[df.SeriesDescription.str.contains("Stacked Screen Save") ==
                False]
        df = df[df.SeriesDescription.str.contains("Screen Save") == False]
    if not args.keep_sequence_information:
        # Trim path.
        df.Path = df.Path.apply(lambda xx: os.path.dirname(xx))
        # Remove duplicates (must be done AFTER path trimming).
        df = df.drop_duplicates(subset='Path', keep="last").reset_index()
    if not args.more_info:
        # df = df.drop(labels='index',                 axis='columns')
        df = df.drop(labels='SeriesDescription', axis='columns')
        df = df.drop(labels='SeriesNumber', axis='columns')
        df = df.drop(labels='SeriesTime', axis='columns')
        df = df.drop(labels='NumFiles', axis='columns')
    if not args.report_files:
        df = df.drop(labels='ImagesInAcquisition', axis='columns')
        df = df.drop(labels='InStackPositionNumber', axis='columns')
        df = df.drop(labels='InstanceNumber', axis='columns')
        df = df.drop(labels='SliceLocation', axis='columns')
        df = df.drop(labels='FloatSlopRTIATimer', axis='columns')
        df = df.drop(labels='TriggerTime', axis='columns')

    print_this(currLog, st.RESET_ALL + fg.GREEN + '* TABLE' + st.RESET_ALL)
    print_this(currLog, tabulate(df, headers='keys', tablefmt="orgtbl"))
    if args.write_csv:
        fn = args.log_file
        df.to_csv(path_or_buf=rchop(fn, '.org') + '.csv', sep=',')