Mercurial > hg > orthanc-book
comparison Sphinx/source/plugins/python/create-dicom.py @ 704:ba2403ebd4b7
moving python samples in separate files (3)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 11 Jun 2021 10:24:08 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
703:a589668768d7 | 704:ba2403ebd4b7 |
---|---|
1 import json | |
2 import orthanc | |
3 | |
4 def OnChange(changeType, level, resource): | |
5 if changeType == orthanc.ChangeType.ORTHANC_STARTED: | |
6 tags = { | |
7 'SOPClassUID' : '1.2.840.10008.5.1.4.1.1.1', | |
8 'PatientID' : 'HELLO', | |
9 'PatientName' : 'WORLD', | |
10 } | |
11 | |
12 with open('Lena.png', 'rb') as f: | |
13 img = orthanc.UncompressImage(f.read(), orthanc.ImageFormat.PNG) | |
14 | |
15 s = orthanc.CreateDicom(json.dumps(tags), img, orthanc.CreateDicomFlags.GENERATE_IDENTIFIERS) | |
16 | |
17 with open('/tmp/sample.dcm', 'wb') as f: | |
18 f.write(s) | |
19 | |
20 dicom = orthanc.CreateDicomInstance(s) | |
21 frame = dicom.GetInstanceDecodedFrame(0) | |
22 print('Size of the frame: %dx%d' % (frame.GetImageWidth(), frame.GetImageHeight())) | |
23 | |
24 orthanc.RegisterOnChangeCallback(OnChange) |