1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#!/bin/sh
#
# usage: dcjpeg infile outfile transfersyntax jpegoptions
#
# e.g. "1.2.840.10008.1.2.4.70 -k 1" is lossless with predictor 1
# e.g. "1.2.840.10008.1.2.4.50 -q 1" is lossy 8 bit table with high quality
# e.g. "1.2.840.10008.1.2.4.51 -ql 1" is lossy 16 bit table with high quality
#
TMPROOT=/tmp/`basename $0`.$$
DCCP=dccp
DCTORAW=dctoraw
DCKEY=dckey
DCENCAP=dcencap
JPEG=pvrg-jpeg
infile="$1"
shift
outfile="$1"
shift
transfersyntax="$1"
shift
components=`$DCKEY -d -k SamplesPerPixel "$infile" 2>&1`
if [ "$components" != 1 ]
then
echo 1>&2 "Only grayscale images supported"
exit 1
fi
precision=`$DCKEY -d -k BitsStored "$infile" 2>&1`
if [ $precision -gt 12 ]
then
if [ "$transfersyntax" = "1.2.840.10008.1.2.4.51" ]
then
echo 1>&2 "Only up to 12 bits supported for extended process lossy compression"
exit 1
elif [ "$transfersyntax" = "1.2.840.10008.1.2.4.50" ]
then
echo 1>&2 "Only up to 8 bits supported for baseline process lossy compression"
exit 1
fi
fi
width=`$DCKEY -d -k Columns "$infile" 2>&1`
height=`$DCKEY -d -k Rows "$infile" 2>&1`
$DCCP -d PixelData "$infile" "$TMPROOT.header"
$DCCP "$infile" "$TMPROOT.big.dcm" -endian big -vr explicit
$DCTORAW -quiet "$TMPROOT.big.dcm" "$TMPROOT.big.raw"
rm "$TMPROOT.big.dcm"
$JPEG -iw "$width" -ih "$height" -p "$precision" $* "$TMPROOT.big.raw" # creates $TMPROOT.big.raw.jpg
rm "$TMPROOT.big.raw"
$DCENCAP "$TMPROOT.header" "$TMPROOT.big.raw.jpg" -ts "$transfersyntax" -of "$outfile"
rm "$TMPROOT.header" "$TMPROOT.big.raw.jpg"
exit 0
|