Mercurial > hg > orthanc
comparison Resources/Samples/Lua/CallImageJ.lua @ 1535:34c8954544e8
sample Lua script to invoke ImageJ on DICOM images
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 13 Aug 2015 13:41:59 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1534:95b3b0260240 | 1535:34c8954544e8 |
---|---|
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 |