Snippets

osimis Compress a DICOM files with various compression type

Created by Alain Mazy

File snippet.txt Added

  • Ignore whitespace
  • Hide word diff
+#!/bin/bash
+# this script creates transcode a DICOM file with all types of compression.
+# it creates one study per compression type
+#
+# note: it has been tested only  only on Windows: you would probably just need to update dcmodify into ./dcmodify and gdcmconv into ./gdcmconv to make it work on Linux
+# prerequisites:
+# you must have DCMTK installed and in your path [http://dicom.offis.de/dcmtk.php.en]
+# you must have GDCM installed and in your path [https://github.com/malaterre/GDCM/releases]
+
+sourceFile=$1
+
+function convertInstance {
+	sourceFile=$1
+	studyId=$2
+	formatName=$3
+	gdcmOptions=$4
+	target=$1_$3
+	
+	echo "convertInstanceing to $formatName"
+	cp -f $1 tmp_$target
+	dcmodify --no-backup -gin -gse --modify "(0020,000d)=$studyId" --modify "(0008,1030)=$formatName"  --insert "(0008,103e)=$formatName" tmp_$target
+	gdcmconv $gdcmOptions -U -i tmp_$target -o $target
+	rm tmp_$target
+}  
+
+function convertInstanceFile {
+	sourceFile=$1
+
+	convertInstance $1 1 raw "--raw"
+	convertInstance $1 2 jpeg "--jpeg"
+	convertInstance $1 3 jpegls "--jpegls"
+	convertInstance $1 4 rle "--rle"
+	convertInstance $1 5 jp2k "--j2k"
+	convertInstance $1 6 jp2klossy100 "--j2k --lossy -q 100"
+	convertInstance $1 7 jp2klossy90 "--j2k --lossy -q 90"
+	convertInstance $1 8 jp2klossy80 "--j2k --lossy -q 80"
+	convertInstance $1 9 jp2klossy75 "--j2k --lossy -q 75"
+	convertInstance $1 10 jp2klossy70 "--j2k --lossy -q 70"
+	convertInstance $1 11 jp2klossy65 "--j2k --lossy -q 65"
+	convertInstance $1 12 jp2klossy60 "--j2k --lossy -q 60"
+	convertInstance $1 13 jp2klossy50 "--j2k --lossy -q 50"
+}
+
+convertInstanceFile $sourceFile
+
+
+# Orthanc does not accept those: convertInstance $1 gzip "--deflated"
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.