Exemplo n.º 1
0
# test.py
"""Temporary test file for pydicom development; will change over revisions
as test various things
"""
# Copyright (c) 2013 Darcy Mason
# This file is part of pydicom, relased under an MIT-style license.
#    See the file license.txt included with this distribution, also
#    available at https://github.com/darcymason/pydicom
#

import pydicom
# pydicom.debug()


if __name__ == "__main__":
    dcmdir = pydicom.read_dicomdir()
    for patrec in dcmdir.patient_records:
        print("Patient: {0.PatientID}: {0.PatientsName}".format(patrec))
        studies = patrec.children
        for study in studies:
            print("    Study {0.StudyID}: {0.StudyDate}:"
                  " {0.StudyDescription}".format(study))
            all_series = study.children
            for series in all_series:
                image_count = len(series.children)
                plural = ('', 's')[image_count > 1]
                print(" " * 8 + "Series {0.SeriesNumber}: {0.SeriesDescription}"
                      " ({1} image{2})".format(series, image_count, plural))
Exemplo n.º 2
0
if __name__ == "__main__":
    print("------------------------------------------------------------")
    print("Example program showing DICOMDIR contents, assuming standard")
    print("Patient -> Study -> Series -> Images hierarchy")
    print("------------------------------------------------------------")
    print()
    if len(sys.argv) > 1:
        filepath = sys.argv[1]
        if os.path.isdir(filepath):  # only gave directory, add standard name
            filepath = os.path.join(filepath, "DICOMDIR")
        dcmdir = read_dicomdir(filepath)
        base_dir = os.path.dirname(filepath)
    else:
        # Read standard "DICOMDIR" filename from current directory
        dcmdir = pydicom.read_dicomdir()
        base_dir = "."

    for patrec in dcmdir.patient_records:
        if hasattr(patrec, 'PatientID') and hasattr(patrec, 'PatientsName'):
            print("Patient: {0.PatientID}: {0.PatientsName}".format(patrec))
        studies = patrec.children
        for study in studies:
            print("    Study {0.StudyID}: {0.StudyDate}:"
                  " {0.StudyDescription}".format(study))
            all_series = study.children
            for series in all_series:
                image_count = len(series.children)
                plural = ('', 's')[image_count > 1]

                # Write basic series info and image count
Exemplo n.º 3
0
import os.path
from pprint import pprint
# pydicom.debug()


if __name__ == "__main__":
    print("------------------------------------------------------------")
    print("Example program showing DICOMDIR contents, assuming standard")
    print("Patient -> Study -> Series -> Images hierarchy")
    print("------------------------------------------------------------")
    print()
    if len(sys.argv) > 1:
        filepath = sys.argv[1]
        if os.path.isdir(filepath):  # only gave directory, add standard name
            filepath = os.path.join(filepath, "DICOMDIR")
        dcmdir = pydicom.read_dicomdir(filepath)
        base_dir = os.path.dirname(filepath)
    else:
        # Read standard "DICOMDIR" filename from current directory
        dcmdir = pydicom.read_dicomdir()
        base_dir = "."

    for patrec in dcmdir.patient_records:
        print("Patient: {0.PatientID}: {0.PatientsName}".format(patrec))
        studies = patrec.children
        for study in studies:
            print("    Study {0.StudyID}: {0.StudyDate}:"
                  " {0.StudyDescription}".format(study))
            all_series = study.children
            for series in all_series:
                image_count = len(series.children)