view Sphinx/source/users/code/image-dicomization.py @ 1121:f45af556efae Orthanc-1.12.5

Orthanc 1.12.5
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 17 Dec 2024 18:46:02 +0100
parents 2d83e9ce6bf0
children
line wrap: on
line source

import base64
import json
import requests

with open('sample.png', 'rb') as f:
    content = f.read()

pixelData = base64.b64encode(content).decode('ascii')

r = requests.post('http://localhost:8042/tools/create-dicom',
                  json.dumps({
                      'Content' : 'data:image/png;base64,%s' % pixelData,
                      'Tags' : {
                          'PatientName' : 'TEST',
                          'StudyDescription' : 'MY^STUDY',
                      }
                  }),
                  auth = requests.auth.HTTPBasicAuth('orthanc', 'orthanc'))
r.raise_for_status()

instanceId = r.json() ['ID']
print('ID of the newly created DICOM instance: %s' % instanceId)