comparison Database/Lua/Jpeg2000Conversion.lua @ 151:b6b207b1de0d Orthanc-1.4.1

missing file
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 17 Jul 2018 11:24:21 +0200
parents
children
comparison
equal deleted inserted replaced
150:4a6b2e036300 151:b6b207b1de0d
1 -- https://groups.google.com/d/msg/orthanc-users/Rc-Beb42xc8/JUgdzrmCAgAJ
2
3 function OnStoredInstance(instanceId, tags, metadata, origin)
4 -- Do not compress twice the same file
5 if origin['RequestOrigin'] ~= 'Lua' then
6
7 -- Retrieve the incoming DICOM instance from Orthanc
8 local dicom = RestApiGet('/instances/' .. instanceId .. '/file')
9
10 -- Write the DICOM content to some temporary file
11 local uncompressed = '/tmp/uncompressed-' .. instanceId .. '.dcm'
12 local target = assert(io.open(uncompressed, 'wb'))
13 target:write(dicom)
14 target:close()
15
16 -- Compress to JPEG2000 using gdcm
17 local compressed = '/tmp/compressed-' .. instanceId .. '.dcm'
18 os.execute('gdcmconv -U --j2k ' .. uncompressed .. ' ' .. compressed)
19
20 -- Generate a new SOPInstanceUID for the JPEG2000 file, as
21 -- gdcmconv does not do this by itself
22 os.execute('dcmodify --no-backup -m "SOPInstanceUID=' ..
23 tags['SOPInstanceUID'] .. '" ' .. compressed)
24
25 local source = assert(io.open(compressed, 'rb'))
26 local jpeg2k = source:read("*all")
27 source:close()
28
29 -- Upload the JPEG2000 file and remove the uncompressed file
30 RestApiDelete('/instances/' .. instanceId)
31 RestApiPost('/instances', jpeg2k)
32
33 -- Remove the temporary DICOM files
34 os.remove(uncompressed)
35 os.remove(compressed)
36 end
37 end