annotate Sphinx/source/plugins/python/create-dicom.py @ 821:d7c8c8f6cffb

removed 'LimitJobs' that is unused
author Alain Mazy <am@osimis.io>
date Mon, 07 Mar 2022 10:58:09 +0100
parents ba2403ebd4b7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
704
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 import json
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 import orthanc
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 def OnChange(changeType, level, resource):
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 if changeType == orthanc.ChangeType.ORTHANC_STARTED:
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 tags = {
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 'SOPClassUID' : '1.2.840.10008.5.1.4.1.1.1',
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 'PatientID' : 'HELLO',
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 'PatientName' : 'WORLD',
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 }
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 with open('Lena.png', 'rb') as f:
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 img = orthanc.UncompressImage(f.read(), orthanc.ImageFormat.PNG)
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 s = orthanc.CreateDicom(json.dumps(tags), img, orthanc.CreateDicomFlags.GENERATE_IDENTIFIERS)
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 with open('/tmp/sample.dcm', 'wb') as f:
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 f.write(s)
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 dicom = orthanc.CreateDicomInstance(s)
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 frame = dicom.GetInstanceDecodedFrame(0)
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 print('Size of the frame: %dx%d' % (frame.GetImageWidth(), frame.GetImageHeight()))
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
ba2403ebd4b7 moving python samples in separate files (3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 orthanc.RegisterOnChangeCallback(OnChange)