Script to compress dicom via `dcmtk` lossless

MichaelHutel-0817 0 Reputation points
2024-10-23T14:29:42.8+00:00
#!/bin/bash

# Compress DICOM images to JPEG-LS Lossless using DCMTK
echo "Compressing DICOM files to JPEG-LS Lossless..."

# Ensure DCMTK is installed
if ! command -v dcmcjpls &> /dev/null; then
    echo "Error: DCMTK is not installed. Install it using 'sudo apt install dcmtk' or 'brew install dcmtk'"
    exit 1
fi

# Define input and output files
INPUT_DCM=$1
OUTPUT_DCM=$2

# Check if input file is provided
if [ -z "$INPUT_DCM" ]; then
    echo "Usage: $0 <input.dcm> [output.dcm]"
    exit 1
fi

# Set default output file name if not provided
if [ -z "$OUTPUT_DCM" ]; then
    OUTPUT_DCM="compressed_$INPUT_DCM"
fi

# Perform JPEG-LS Lossless compression using DCMTK
dcmcjpls "$INPUT_DCM" "$OUTPUT_DCM"

# Check compression success
if [ $? -eq 0 ]; then
    echo "Compression successful: $OUTPUT_DCM"
    dcmdump "$OUTPUT_DCM" | grep TransferSyntaxUID
else
    echo "Compression failed."
fi

Developer technologies | C++
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.