comparison OrthancServer/Resources/Samples/Lua/CallImageJ.lua @ 4044:d25f4c0fa160 framework

splitting code into OrthancFramework and OrthancServer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 10 Jun 2020 20:30:34 +0200
parents Resources/Samples/Lua/CallImageJ.lua@34c8954544e8
children
comparison
equal deleted inserted replaced
4043:6c6239aec462 4044:d25f4c0fa160
1 -- This sample shows how to invoke an ImageJ script on every DICOM
2 -- image received by Orthanc. The ImageJ script is generated by the
3 -- "Initialize()" function at the startup of Orthanc. Whenever a new
4 -- instance is received, its DICOM file is stored into a temporary
5 -- file, and a system call to ImageJ is triggered.
6
7 SCRIPT = 'ImageJScript.txt'
8
9 function Initialize()
10 local target = assert(io.open(SCRIPT, 'w'))
11
12 -- This is a sample ImageJ script that display the size of the DICOM image
13 target:write('if (getArgument=="") exit ("No argument!");\n')
14 target:write('open(getArgument);\n')
15 target:write('print(getTitle + ": " + getWidth + "x" + getHeight);\n')
16
17 target:close()
18 end
19
20 function OnStoredInstance(instanceId)
21 -- Retrieve the DICOM instance from Orthanc
22 local dicom = RestApiGet('/instances/' .. instanceId .. '/file')
23
24 -- Write the DICOM content to some temporary file
25 local path = instanceId .. '.dcm'
26 local target = assert(io.open(path, 'wb'))
27 target:write(dicom)
28 target:close()
29
30 -- Call ImageJ
31 os.execute('imagej -b ' .. SCRIPT .. ' ' .. path)
32
33 -- Remove the temporary DICOM file
34 os.remove(path)
35 end