view Sphinx/source/plugins/python/create-dicom.py @ 818:48676fb3ac0f

Added tag Orthanc-1.10.0 for changeset 01fa632daae9
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 23 Feb 2022 15:03:47 +0100
parents ba2403ebd4b7
children
line wrap: on
line source

import json
import orthanc

def OnChange(changeType, level, resource):
    if changeType == orthanc.ChangeType.ORTHANC_STARTED:
        tags = {
            'SOPClassUID' : '1.2.840.10008.5.1.4.1.1.1',
            'PatientID' : 'HELLO',
            'PatientName' : 'WORLD',
        }

        with open('Lena.png', 'rb') as f:
            img = orthanc.UncompressImage(f.read(), orthanc.ImageFormat.PNG)

        s = orthanc.CreateDicom(json.dumps(tags), img, orthanc.CreateDicomFlags.GENERATE_IDENTIFIERS)

        with open('/tmp/sample.dcm', 'wb') as f:
            f.write(s)

        dicom = orthanc.CreateDicomInstance(s)
        frame = dicom.GetInstanceDecodedFrame(0)
        print('Size of the frame: %dx%d' % (frame.GetImageWidth(), frame.GetImageHeight()))

orthanc.RegisterOnChangeCallback(OnChange)