Hi Friends,
I need some help. Before I ask my question, let me setup the scenario. I am using OrthanC as a mini-PACS to serve studies locally in a hospital. It also forwards these studies to a cloud based PACS server (which is also an OrthanC instance).
Since the internet connection is a little iffy at the hospital, I am trying to get the mini-PACS to achieve maximum compression before sending out the studies. I was thinking of combining the J2K compression lua script + sendmodality function to send these studies out (script below)
It would be great to also be able to accomplish these before sending them out:
1. Gzip as a single archive. (Can the cloud-PACS OrthanC accept gzipped studies?)
2. Lossy compression - I have found a value of "-q 85" (approx 1:8 compression) works well with no noticeable loss in quality. This was confirmed by a certified Radiologist.
This is the code I have until now.
function OnStoredInstance(instanceId, tags, metadata, origin)
-- Do not compress twice the same file
if origin['RequestOrigin'] ~= 'Lua' then
-- Retrieve the incoming DICOM instance from Orthanc
local dicom = RestApiGet('/instances/' .. instanceId .. '/file')
-- Write the DICOM content to some temporary file
local uncompressed = instanceId .. '-uncompressed.dcm'
local target = assert(io.open(uncompressed, 'wb'))
target:write(dicom)
target:close()
-- Compress to JPEG2000 using gdcm
local compressed = instanceId .. '-compressed.dcm'
os.execute('gdcmconv --j2k ' .. uncompressed .. ' ' .. compressed)
-- Generate a new SOPInstanceUID for the JPEG2000 file, as
-- gdcmconv does not do this by itself
os.execute('dcmodify --no-backup -gin ' .. compressed)
-- Read the JPEG2000 file
local source = assert(io.open(compressed, 'rb'))
local jpeg2k = source:read("*all")
source:close()
-- Upload the JPEG2000 file and remove the uncompressed file
RestApiPost('/instances', jpeg2k)
RestApiDelete('/instances/' .. instanceId)
-- Remove the temporary DICOM files
os.remove(uncompressed)
os.remove(compressed)
end
SendToModality(instanceId, 'sample')
end