Last active
March 25, 2017 15:16
-
-
Save yohhoy/5e5ae5e169d72489358fb181b6d8e38f to your computer and use it in GitHub Desktop.
RD-curve evaluation of libjpeg/mozjpeg encoder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LIBJPEG=/usr/local/opt/jpeg/bin/cjpeg | |
MOZJPEG=/usr/local/opt/mozjpeg/bin/cjpeg | |
LIBJEPG_OPTS="" | |
MOZJPEG_OPTS="" | |
QRANGE=`seq 80 100` | |
# ImageMagick | |
IDENTIFY=/usr/local/opt/imagemagick/bin/identify | |
CONVERT=/usr/local/opt/imagemagick/bin/convert | |
COMPARE=/usr/local/opt/imagemagick/bin/compare | |
# gnuplot | |
GNUPLOT=/usr/local/opt/gnuplot/bin/gnuplot | |
if [ ! -f "$1" ]; then | |
echo "usage: $0 <target>" | |
exit 1 | |
fi | |
INFILE=$1 | |
IMGINFO=`$IDENTIFY -format '%m,%wx%h' "$INFILE"` | |
echo -e "input: $INFILE (${IMGINFO})" | |
if [ -d ./tmp ]; then | |
WORKDIR=./tmp | |
else | |
WORKDIR=`mktemp -d` | |
fi | |
SRCFILE=$WORKDIR/${INFILE%.*}.ppm | |
DATFILE=$WORKDIR/${INFILE%.*}.dat | |
GRAPHFILE=rdcurve-${INFILE%.*}.png | |
echo "convert:" `basename "$SRCFILE"` | |
$CONVERT "$INFILE" "$SRCFILE" | |
echo -e "#$INFILE\t${IMGINFO}" > $DATFILE | |
echo "libjpeg encoding: ${LIBJEPG_OPTS}" | |
for Q in $QRANGE; do | |
DSTFILE=$WORKDIR/libjpeg-q$Q.jpeg | |
$LIBJPEG -quality $Q ${LIBJEPG_OPTS} "$SRCFILE" > "$DSTFILE" | |
RATE=`wc -c "$DSTFILE" | awk '{print $1}'` | |
DIST=`$COMPARE -metric PSNR "$SRCFILE" "$DSTFILE" /dev/null 2>&1` | |
echo -e "libjpeg\t$Q\t$RATE\t$DIST" >> $DATFILE | |
done | |
echo "mozjpeg encoding: ${MOZJPEG_OPTS}" | |
echo -e "\n\n#mozjpeg" >> $DATFILE | |
for Q in $QRANGE; do | |
DSTFILE=$WORKDIR/mozjpeg-q$Q.jpeg | |
$MOZJPEG -quality $Q ${MOZJPEG_OPTS} "$SRCFILE" > "$DSTFILE" | |
RATE=`wc -c "$DSTFILE" | awk '{print $1}'` | |
DIST=`$COMPARE -metric PSNR "$SRCFILE" "$DSTFILE" /dev/null 2>&1` | |
echo -e "mozjpeg\t$Q\t$RATE\t$DIST" >> $DATFILE | |
done | |
echo "write: ${GRAPHFILE}" | |
TITLE="${INFILE%.*} (${IMGINFO})" | |
SCALE=$((`$IDENTIFY -format '%w' "$SRCFILE"` * `$IDENTIFY -format '%h' "$SRCFILE"`)) | |
$GNUPLOT << EOT | |
set terminal png medium | |
set output "${GRAPHFILE}" | |
set title "${TITLE}" | |
set xlabel "Bitrate [bit/pixel]" | |
set ylabel "PSNR [dB]" | |
set key left top | |
plot "${DATFILE}" index 0 using (8*\$3/${SCALE}):4 with linespoints title "libjpeg", \ | |
"${DATFILE}" index 1 using (8*\$3/${SCALE}):4 with linespoints title "mozjpeg" | |
EOT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment