annotate Resources/Samples/Lua/CallImageJ.lua @ 2313:d19e716b79fa issue-46-anonymization

switch to anonymization according to DICOM 2017c
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Jul 2017 22:07:07 +0200
parents 34c8954544e8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1535
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 -- This sample shows how to invoke an ImageJ script on every DICOM
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 -- image received by Orthanc. The ImageJ script is generated by the
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 -- "Initialize()" function at the startup of Orthanc. Whenever a new
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 -- instance is received, its DICOM file is stored into a temporary
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 -- file, and a system call to ImageJ is triggered.
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 SCRIPT = 'ImageJScript.txt'
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 function Initialize()
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 local target = assert(io.open(SCRIPT, 'w'))
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 -- This is a sample ImageJ script that display the size of the DICOM image
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 target:write('if (getArgument=="") exit ("No argument!");\n')
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 target:write('open(getArgument);\n')
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 target:write('print(getTitle + ": " + getWidth + "x" + getHeight);\n')
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 target:close()
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 end
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 function OnStoredInstance(instanceId)
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 -- Retrieve the DICOM instance from Orthanc
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 local dicom = RestApiGet('/instances/' .. instanceId .. '/file')
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 -- Write the DICOM content to some temporary file
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 local path = instanceId .. '.dcm'
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 local target = assert(io.open(path, 'wb'))
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 target:write(dicom)
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 target:close()
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 -- Call ImageJ
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 os.execute('imagej -b ' .. SCRIPT .. ' ' .. path)
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 -- Remove the temporary DICOM file
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 os.remove(path)
34c8954544e8 sample Lua script to invoke ImageJ on DICOM images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 end