snibgo's ImageMagick pages

Outputs: speed and size

For simple image processing, writing the output can take a significant proportion of the overall time.

Tests were performed on a laptop with Intel Core i7 processor and 12 GB RAM and 1 TB internal disk, under Windows 8.1, with the pre-built integer Q16 ImageMagick binary.

Sample input images

Image compression algorithms are designed for specific image types, so their effectiveness varies according to how closely the image fits the type. We will test with two images: a large digital photograph, and a small graphic with flat colours. Both these images will be subjected to a range of compression methods available in ImageMagick.

Sample photo

zp_sus_sat.tiff is fairly typical of my photographs.

%IM%identify zp_sus_sat.tiff 
zp_sus_sat.tiff TIFF 4924x7378 4924x7378+0+0 16-bit sRGB 167.9MB 0.000u 0:00.015
for /F "usebackq" %%S in (`%IM%identify ^
  -precision 15 ^
  -format "%%[fx:w*h*6]" ^
  zp_sus_sat.tiff`) do set PH_BYTES=%%S

echo PH_BYTES=%PH_BYTES% 
PH_BYTES=217975632 

PH_BYTES is the number of bytes required for the pixels, not compressed.

Here is a reduced-size version:

%IM%convert zp_sus_sat.tiff -resize 600x400 ss_ph_sm.jpg
ss_ph_sm.jpg

Sample graphic

For a graphic image, with flat colours but anti-aliasing around shapes, we will create a smaller image.

%IM%convert ^
  -size 600x400 xc:khaki ^
  -fill #f92 ^
  -draw "circle 200,200 200,350" ^
  ( -size 600x400 xc:None ^
    -fill #29f ^
    -draw "polygon 200,100 550,200 300,50" ^
    -fill #2f9 ^
    -draw "rectangle 50,275 550,375" ^
    -channel A -evaluate Multiply 0.8 +channel ^
  ) ^
  -composite ^
  -alpha off ^
  ss_gr_in.png
ss_gr_in.png
%IM%identify ss_gr_in.png 
ss_gr_in.png PNG 600x400 600x400+0+0 16-bit sRGB 15.6KB 0.000u 0:00.000
for /F "usebackq" %%S in (`%IM%identify ^
  -precision 15 ^
  -format "%%[fx:w*h*6]" ^
  ss_gr_in.png`) do set GR_BYTES=%%S

echo GR_BYTES=%GR_BYTES% 
GR_BYTES=1440000 

GR_BYTES is the number of bytes required for the pixels, not compressed.

TIFF file output

The script compSpd.bat measures the speed of writing a file at various compressions. It does this by timing the appropriate convert command, and subtracting the time required for the same command that outputs to NULL:.

It also compares the output with the original, giving a number between zero and one. As a rule of thumb, a difference of less than 0.01 (1%) looks the same as the original.

TIFF of photo

del ph_summ.csv >nul

call %PICTBAT%compSpd zp_sus_sat.tiff ss_tiff tiff 5 ph_summ.csv
-compress Seconds Compression % Difference
B44 0.4906s 100.03% 0
B44A 0.2842s 100.03% 0
BZip 0.2842s 100.03% 0
DXT1 0.2906s 100.03% 0
DXT3 0.2874s 100.03% 0
DXT5 0.278s 100.03% 0
Fax 18.85s 1.88% 0.392614
Group4 19.1844s 2.18% 0.392614
JBIG1 0.3092s 100.03% 0
JBIG2 0.2968s 100.03% 0
JPEG 0.6312s 3.72% 0.00826742
JPEG2000 0.3968s 100.03% 0
Lossless 0.2874s 100.03% 0
LosslessJPEG 0.275s 100.03% 0
LZMA 0.2936s 100.03% 0
LZW 4.228s 99.8% 0
None 0.353s 100.03% 0
Piz 0.2686s 100.03% 0
Pxr24 0.2906s 100.03% 0
RLE 1.028s 100.79% 0
Zip 15.2032s 77.03% 0
RunlengthEncoded 1.0342s 100.79% 0
ZipS 0.275s 100.03% 0

The smallest lossless compression method is ZIP. But it is slow.

-compress None is fast. JPEG compression takes twice as long, but the file size is much smaller.

When ZIP compression is enabled, writing to TIFF is also sensitive to -quality:

call %PICTBAT%qual99Spd zp_sus_sat.tiff ss_tiff_z tiff 5 ph_summ.csv
-quality 0 1..9
00 15.1876s
77.03%
4.0312s
100.02%
10 10.3782s
79.23%
10.4188s
79.23%
20 10.8844s
78.91%
10.9376s
78.91%
30 11.4876s
78.44%
11.4844s
78.44%
40 12.9938s
77.46%
13.5722s
77.46%
50 15.0688s
77.11%
14.8088s
77.11%
60 15.2934s
77.04%
14.9938s
77.04%
70 15.1314s
77.03%
15.1222s
77.03%
80 15.1314s
77.03%
15.15s
77.03%
90 15.1376s
77.03%
15.1s
77.03%

-quality 0 is equivalent to -quality 70. Lower quality numbers give shorter times and larger files. The quality with the shortest time is highlighted.

TIFF of graphic

del gr_summ.csv >nul

call %PICTBAT%compSpd ss_gr_in.png ss_gr_tiff tiff 100 gr_summ.csv
-compress Seconds Compression % Difference
B44 0.02125s 100.13% 0
B44A 0.02578s 100.13% 0
BZip 0.02703s 100.13% 0
DXT1 0.02704s 100.13% 0
DXT3 0.025s 100.13% 0
DXT5 0.02735s 100.13% 0
Fax 0.11735s 1.36% 0.470341
Group4 0.11875s 1.62% 0.470341
JBIG1 0.03422s 100.13% 0
JBIG2 0.02485s 100.13% 0
JPEG 0.02235s 1.5% 0.00480253
JPEG2000 0.02532s 100.13% 0
Lossless 0.02407s 100.13% 0
LosslessJPEG 0.02422s 100.13% 0
LZMA 0.03375s 100.13% 0
LZW 0.025s 3.47% 0
None 0.03157s 100.13% 0
Piz 0.02282s 100.13% 0
Pxr24 0.02469s 100.13% 0
RLE 0.02875s 100.38% 0
Zip 0.02313s 1.14% 0
RunlengthEncoded 0.0325s 100.38% 0
ZipS 0.02516s 100.13% 0

For this graphic image, ZIP is slightly faster than -compress None, and the filesize is reduced by about 99%. LZW can be slightly faster, but larger, than ZIP at default quality.

When ZIP compression is enabled, writing to TIFF is also sensitive to -quality:

call %PICTBAT%qual99Spd ss_gr_in.png ss_gr_tiff_z tiff 100 gr_summ.csv
-quality 0 1..9
00 0.0339s
1.14%
0.03046s
100.03%
10 0.02484s
1.59%
0.02031s
1.59%
20 0.01937s
1.59%
0.02125s
1.59%
30 0.01875s
1.56%
0.01968s
1.56%
40 0.02828s
1.13%
0.02546s
1.13%
50 0.02625s
1.14%
0.02421s
1.14%
60 0.02828s
1.14%
0.02734s
1.14%
70 0.02781s
1.14%
0.02812s
1.14%
80 0.03859s
1.11%
0.03781s
1.11%
90 0.04812s
1.05%
0.04578s
1.05%

-quality 0 is equivalent to -quality 70. Lower quality numbers give shorter times and larger files.

MIFF file output

MIFF of photo

call %PICTBAT%compSpd zp_sus_sat.tiff ss_miff miff 5 ph_summ.csv
-compress Seconds Compression % Difference
B44 0.2906s 100% 0
B44A 0.2186s 100% 0
BZip 34.3846s 99.52% 0
DXT1 0.2594s 100% 0
DXT3 0.2218s 100% 0
DXT5 0.2218s 100% 0
Fax 0.2312s 100% 0
Group4 0.2312s 100% 0
JBIG1 0.2218s 100% 0
JBIG2 0.2218s 100% 0
JPEG 0.2218s 100% 0
JPEG2000 0.2156s 100% 0
Lossless 0.225s 100% 0
LosslessJPEG 0.2656s 100% 0
LZMA 0.2186s 100% 0
LZW 9.2968s 96.73% 0
None 0.2844s 100% 0
Piz 0.225s 100% 0
Pxr24 0.2656s 100% 0
RLE 0.5468s 116.62% 0
Zip 9.2718s 96.73% 0
RunlengthEncoded 0.6218s 116.62% 0
ZipS 0.2218s 100% 0

For MIFF, all compressions are lossless. ZIP and LZW give some compression, but it is very slight, with a large penalty in speed (roughly factor 40).

When ZIP compression is enabled, writing to MIFF is also sensitive to -quality:

call %PICTBAT%qual99Spd zp_sus_sat.tiff ss_miff_z miff 5 ph_summ.csv
-quality 0 1..9
00 9.1656s
96.73%
1.05s
100.050%
10 8.9406s
96.66%
8.8312s
96.66%
20 8.847s
96.64%
8.9812s
96.64%
30 8.8812s
96.64%
8.8656s
96.64%
40 9.272s
96.74%
9.2064s
96.74%
50 9.225s
96.73%
9.1626s
96.73%
60 9.1938s
96.73%
9.222s
96.73%
70 9.3032s
96.73%
9.2688s
96.73%
80 9.2094s
96.73%
9.2406s
96.73%
90 9.2032s
96.73%
9.2562s
96.73%

Changing the quality changes the size. However, for this photograph, there is not much change in size or procesing time. The smallest size is from -quality 1, no compression. Between settings that give compression, there is little difference in speed or size.

MIFF of graphic

call %PICTBAT%compSpd ss_gr_in.png ss_gr_miff miff 100 gr_summ.csv
-compress Seconds Compression % Difference
B44 0.00516s 100.06% 0
B44A 0.00438s 100.06% 0
BZip 0.12234s 3.19% 0
DXT1 0.00766s 100.06% 0
DXT3 0.00375s 100.06% 0
DXT5 0.00344s 100.06% 0
Fax 0.00281s 100.06% 0
Group4 0.00531s 100.06% 0
JBIG1 0.00406s 100.06% 0
JBIG2 0.00375s 100.06% 0
JPEG 0.00484s 100.06% 0
JPEG2000 0.00469s 100.06% 0
Lossless 0.00453s 100.06% 0
LosslessJPEG 0.00406s 100.06% 0
LZMA 0.00484s 100.06% 0
LZW 0.01344s 1.64% 0
None 0.00281s 100.06% 0
Piz 0.00375s 100.06% 0
Pxr24 0.00563s 100.06% 0
RLE 0.00422s 1.98% 0
Zip 0.01391s 1.64% 0
RunlengthEncoded 0.005s 1.98% 0
ZipS 0.005s 100.06% 0

As with the photograph, -compress None is the quickest, more or less. For this graphic, ZIP is about one-fortieth of the uncompressed size, with a speed penalty factor of less than 5. LZW is slightly faster than ZIP.

When ZIP compression is enabled, writing to MIFF is also sensitive to -quality:

call %PICTBAT%qual99Spd ss_gr_in.png ss_gr_miff_z miff 100 gr_summ.csv
-quality 0 1..9
00 0.01375s
1.64%
0.00891s
100.450%
10 0.00828s
1.98%
0.00875s
1.98%
20 0.00797s
1.98%
0.00844s
1.98%
30 0.01063s
1.96%
0.00969s
1.96%
40 0.0125s
1.68%
0.01235s
1.68%
50 0.01235s
1.67%
0.0125s
1.67%
60 0.01313s
1.65%
0.01391s
1.65%
70 0.0125s
1.64%
0.01344s
1.64%
80 0.01625s
1.55%
0.01563s
1.55%
90 0.02063s
1.55%
0.01969s
1.55%

For this graphic, changing quality has a significant effect on size and processing time. The smallest size, and longest time, are from -quality 90.

MPC file output

For the MPC format, the size shown is of the .CACHE file. The MPC file is always about 550 bytes.

MPC of photo

call %PICTBAT%compSpd zp_sus_sat.tiff ss_mpc mpc 5 ph_summ.csv
-compress Seconds Compression % Difference
B44 1.1032s 133.33% 0
B44A 2.7316s 133.33% 0
BZip 2.7938s 133.33% 0
DXT1 2.7782s 133.33% 0
DXT3 2.7564s 133.33% 0
DXT5 2.7752s 133.33% 0
Fax 2.8126s 133.33% 0
Group4 0.8s 133.33% 0
JBIG1 2.7846s 133.33% 0
JBIG2 2.6876s 133.33% 0
JPEG 2.7344s 133.33% 0
JPEG2000 2.7096s 133.33% 0
Lossless 2.7908s 133.33% 0
LosslessJPEG 2.7814s 133.33% 0
LZMA 2.7002s 133.33% 0
LZW 2.8096s 133.33% 0
None 2.7346s 133.33% 0
Piz 2.7782s 133.33% 0
Pxr24 2.8126s 133.33% 0
RLE 0.1032s 133.33% 0
Zip 3.291s 133.33% 0
RunlengthEncoded 2.8814s 133.33% 0
ZipS 2.7658s 133.33% 0

Like MIFF, all MPC compressions are lossless.

Why is there a speed variation, even though there is no size variation? I don't know.

For -compress None, MPC is about half the speed of MIFF. The files are 33% larger, because it also stores alpha values. So, for this photograph, MPC has no advantage over MIFF.

MPC of graphic

call %PICTBAT%compSpd ss_gr_in.png ss_gr_mpc mpc 100 gr_summ.csv
-compress Seconds Compression % Difference
B44 0.00063s 133.33% 0
B44A 0.00188s 133.33% 0
BZip 0.00281s 133.33% 0
DXT1 0.00156s 133.33% 0
DXT3 0.00016s 133.33% 0
DXT5 0.00203s 133.33% 0
Fax 0.00016s 133.33% 0
Group4 0.00094s 133.33% 0
JBIG1 0.00141s 133.33% 0
JBIG2 0.00125s 133.33% 0
JPEG 0.00109s 133.33% 0
JPEG2000 0.00078s 133.33% 0
Lossless 0.00141s 133.33% 0
LosslessJPEG 0.00078s 133.33% 0
LZMA -0.00031s 133.33% 0
LZW 0.00094s 133.33% 0
None 0.00047s 133.33% 0
Piz 0.00094s 133.33% 0
Pxr24 0.00172s 133.33% 0
RLE 0.00141s 133.33% 0
Zip 0.00172s 133.33% 0
RunlengthEncoded 0.00109s 133.33% 0
ZipS 0.00078s 133.33% 0

For this graphic, some times are negative, so writing the file took less time than writing to NULL:.

PNG file output

For the PNG file format, compression is controlled by the -quality setting. PNG compression is always lossless. The -quality setting affects the speed and size. For a description of this setting see the official ImageMagick: Command-line Options: quality.

The script qual99Spd.bat tries 100 quality settings, from 0 to 99. The table show two numbers for each quality setting: the time in seconds, and the file size in bytes.

PNG of photo

call %PICTBAT%qual99Spd zp_sus_sat.tiff ss_png png 5 ph_summ.csv
-quality 0 1 2 3 4 5 6 7 8 9
00 23.3158s
76.13%
3.2312s
97.79%
3.1876s
97.79%
3.425s
97.79%
3.347s
97.79%
9s
77.77%
9.0594s
77.77%
8.997s
77.77%
8.975s
77.77%
8.9844s
77.77%
10 14.2688s
79.16%
8.9938s
96.95%
9.0156s
96.95%
8.9438s
96.95%
9.0126s
96.95%
14.3032s
79.16%
14.2438s
79.16%
14.2282s
79.16%
8.9406s
77.8%
8.9656s
77.8%
20 15.1408s
78.96%
9.2594s
96.93%
9.2158s
96.93%
9.0844s
96.93%
9.0656s
96.93%
14.8594s
78.96%
14.9688s
78.96%
14.8938s
78.96%
9.097s
77.8%
8.9876s
77.8%
30 15.6438s
78.58%
9.0126s
96.93%
9s
96.93%
8.9688s
96.93%
9.0188s
96.93%
15.6658s
78.58%
15.6658s
78.58%
15.6658s
78.58%
8.972s
77.8%
8.9844s
77.8%
40 18.8814s
76.4%
9.3032s
97.73%
9.3344s
97.73%
9.3564s
97.73%
9.3688s
97.73%
19.0158s
76.4%
19.0782s
76.4%
18.7752s
76.4%
8.975s
77.8%
8.9938s
77.8%
50 20.2252s
76.25%
9.475s
97.73%
9.3564s
97.73%
9.35s
97.73%
9.3688s
97.73%
20.2502s
76.25%
20.5908s
76.25%
20.494s
76.25%
9.1032s
77.8%
9.0188s
77.8%
60 22.9908s
76.16%
9.2532s
97.73%
9.2438s
97.73%
9.197s
97.73%
9.3594s
97.73%
22.8032s
76.16%
22.9064s
76.16%
23.1502s
76.16%
9.1626s
77.8%
9.3514s
77.8%
70 24.4114s
76.13%
9.9986s
97.73%
9.8364s
97.73%
9.4792s
97.73%
9.3778s
97.73%
23.8834s
76.13%
24.111s
76.13%
24.1424s
76.13%
9.1216s
77.8%
9.1334s
77.8%
80 25.0916s
76.11%
9.6332s
97.73%
9.4468s
97.73%
9.5812s
97.73%
9.675s
97.73%
25.667s
76.11%
24.997s
76.11%
24.74s
76.11%
8.972s
77.8%
8.8688s
77.8%
90 24.147s
76.11%
9.275s
97.73%
9.3032s
97.73%
9.2626s
97.73%
9.2408s
97.73%
24.1408s
76.11%
24.2064s
76.11%
24.2752s
76.11%
8.8094s
77.8%
8.8406s
77.8%

The default quality setting of 75 gives roughly the smallest file, and takes roughly the longest. For the quickest time, -quality 8 is a good choice. It takes about 15 times as long as TIFF with no compression, and 50 times as long as MIFF with no compression.

For this photograph, the ratio between the worst and best times is more than 8:1.

PNG of graphic

call %PICTBAT%qual99Spd ss_gr_in.png ss_gr_png png 100 gr_summ.csv
-quality 0 1 2 3 4 5 6 7 8 9
00 0.02188s
1.08%
0.01766s
38.04%
0.01782s
38.04%
0.01782s
38.04%
0.01735s
38.04%
0.02578s
13.58%
0.0261s
13.58%
0.02594s
13.58%
0.02625s
13.58%
0.02625s
13.58%
10 0.01453s
1.52%
0.00828s
1.31%
0.00672s
1.31%
0.00703s
1.31%
0.0075s
1.31%
0.01469s
1.52%
0.01532s
1.52%
0.015s
1.52%
0.01422s
1.43%
0.01422s
1.43%
20 0.015s
1.51%
0.00735s
1.31%
0.00657s
1.31%
0.00641s
1.31%
0.00735s
1.31%
0.01453s
1.51%
0.01469s
1.51%
0.01501s
1.51%
0.01391s
1.43%
0.01438s
1.43%
30 0.01532s
1.5%
0.00641s
1.28%
0.00672s
1.28%
0.00703s
1.28%
0.00688s
1.28%
0.01516s
1.5%
0.01438s
1.5%
0.01453s
1.5%
0.01407s
1.43%
0.01391s
1.43%
40 0.01985s
1.07%
0.01032s
0.96%
0.01094s
0.96%
0.01219s
0.96%
0.01125s
0.96%
0.01985s
1.07%
0.01922s
1.07%
0.01953s
1.07%
0.01469s
1.43%
0.01407s
1.43%
50 0.01953s
1.07%
0.01125s
0.96%
0.01094s
0.96%
0.01141s
0.96%
0.01141s
0.96%
0.01922s
1.07%
0.02016s
1.07%
0.01907s
1.07%
0.01547s
1.43%
0.01469s
1.43%
60 0.02157s
1.08%
0.0111s
0.95%
0.01125s
0.95%
0.01219s
0.95%
0.01157s
0.95%
0.02203s
1.08%
0.02203s
1.08%
0.02172s
1.08%
0.015s
1.43%
0.01422s
1.43%
70 0.02297s
1.08%
0.01188s
0.94%
0.01203s
0.94%
0.01172s
0.94%
0.01141s
0.94%
0.02172s
1.08%
0.02313s
1.08%
0.02188s
1.08%
0.01485s
1.43%
0.01469s
1.43%
80 0.03141s
1.05%
0.01407s
0.82%
0.01453s
0.82%
0.01485s
0.82%
0.01453s
0.82%
0.03141s
1.05%
0.03141s
1.05%
0.03141s
1.05%
0.01516s
1.43%
0.01453s
1.43%
90 0.04203s
1.01%
0.01719s
0.83%
0.01766s
0.83%
0.01719s
0.83%
0.0175s
0.83%
0.0425s
1.01%
0.0425s
1.01%
0.04219s
1.01%
0.01407s
1.43%
0.01469s
1.43%

For this graphic image, the default quality 75 is worse in both speed and size than some other qualities, such as 47, 57, ... 97. The quickest quality is higlighted. Good choices for speed include 10, 11, 20, 21, 30, 31.

If the very smallest PNG is desired, the pngcrush program can be used.

JPG file output

Just for fun, I repeat the test for JPG compression. I don't use jpegs unless I really have to, or for final output to the web. Jpeg files are only 8 bits/channel/pixel, and compression is always lossy.

Lossy compresson means the compressed image is different to the input. The table shows the difference at each quality setting. So the three numbers are:

JPG of photo

call %PICTBAT%qual99Spd zp_sus_sat.tiff ss_jpg jpg 5 ph_summ.csv
-quality 0 1 2 3 4 5 6 7 8 9
00 0.8314s
3.78%
0.00859206
0.3s
0.12%
0.0661949
0.3126s
0.12%
0.0661942
0.3032s
0.12%
0.065476
0.3094s
0.13%
0.0549733
0.3156s
0.15%
0.0449441
0.3126s
0.16%
0.0401622
0.3156s
0.18%
0.0366245
0.3126s
0.19%
0.0339294
0.3156s
0.21%
0.0319626
10 0.3156s
0.23%
0.0297613
0.3188s
0.24%
0.028501
0.322s
0.26%
0.0275573
0.3314s
0.27%
0.026298
0.3188s
0.29%
0.0255071
0.325s
0.3%
0.0244896
0.3282s
0.32%
0.0238455
0.3406s
0.33%
0.0232035
0.3344s
0.35%
0.0227208
0.3314s
0.36%
0.0222314
20 0.3406s
0.38%
0.0216718
0.3314s
0.39%
0.0211871
0.3376s
0.4%
0.0209028
0.3376s
0.42%
0.0206344
0.3406s
0.43%
0.0201075
0.3344s
0.45%
0.0198594
0.3344s
0.46%
0.0196288
0.3626s
0.47%
0.0193125
0.3532s
0.49%
0.0191143
0.3406s
0.5%
0.0189458
30 0.3438s
0.51%
0.0187502
0.35s
0.52%
0.0184998
0.3438s
0.53%
0.0183391
0.347s
0.55%
0.0180376
0.347s
0.55%
0.0179093
0.347s
0.57%
0.0177449
0.347s
0.58%
0.0175628
0.3532s
0.59%
0.0174767
0.35s
0.6%
0.0173499
0.3564s
0.61%
0.0172411
40 0.35s
0.62%
0.0171337
0.35s
0.63%
0.016966
0.3656s
0.64%
0.0168894
0.3594s
0.65%
0.0168214
0.3564s
0.67%
0.0166522
0.3594s
0.67%
0.0166108
0.3844s
0.69%
0.0164567
0.3844s
0.69%
0.0164132
0.375s
0.71%
0.0163603
0.3626s
0.72%
0.0161533
50 0.3626s
0.72%
0.0161309
0.3594s
0.73%
0.0161069
0.3626s
0.75%
0.0159484
0.3656s
0.76%
0.015892
0.372s
0.77%
0.0158393
0.3656s
0.78%
0.0157727
0.375s
0.79%
0.0157048
0.372s
0.81%
0.015616
0.372s
0.83%
0.0155147
0.3782s
0.84%
0.0154657
60 0.375s
0.85%
0.0153884
0.375s
0.87%
0.0152685
0.372s
0.88%
0.0152167
0.3876s
0.9%
0.0151293
0.3906s
0.91%
0.0150292
0.3814s
0.94%
0.014938
0.3844s
0.95%
0.0148491
0.3906s
0.97%
0.0147482
0.4126s
1%
0.0146476
0.3906s
1.02%
0.0145589
70 0.3938s
1.05%
0.014456
0.3938s
1.07%
0.0143243
0.4032s
1.09%
0.0142573
0.3938s
1.13%
0.014146
0.4032s
1.17%
0.0140064
0.4094s
1.18%
0.0139671
0.397s
1.21%
0.0138165
0.4094s
1.26%
0.0136667
0.4126s
1.31%
0.0135965
0.4156s
1.34%
0.0135082
80 0.422s
1.39%
0.0133582
0.422s
1.44%
0.0132206
0.4344s
1.49%
0.0131011
0.4406s
1.57%
0.0129542
0.4406s
1.62%
0.0128183
0.45s
1.68%
0.0126594
0.4626s
1.79%
0.0124898
0.4564s
1.85%
0.01233
0.4782s
1.98%
0.0121341
0.4782s
2.07%
0.011956
90 0.8s
3.33%
0.00906886
0.8032s
3.57%
0.00881977
0.825s
3.78%
0.00859206
0.8564s
4.18%
0.00824284
0.9188s
4.71%
0.0078456
0.9406s
5.3%
0.00738749
1.0282s
6.31%
0.00671621
1.1376s
7.47%
0.0059638
1.3032s
9.1%
0.00498795
1.6376s
12.47%
0.00379436

Except for -quality 0, increasing the quality number increases the file size and elapsed time, more or less. -quality 0 gives the same file size as -quality 92.

My rule-of-thumb "less than 1% difference" is achieved for quality levels at or above 90. If we tolerate a 2% difference, a quality of 25 or above will give this.

JPG of graphic

call %PICTBAT%qual99Spd ss_gr_in.png ss_gr_jpg jpg 100 gr_summ.csv
-quality 0 1 2 3 4 5 6 7 8 9
00 0.00562s
1.26%
0.0049451
0.00171s
0.14%
0.0770259
0.0025s
0.14%
0.0770259
0.00109s
0.14%
0.0769915
0.00281s
0.15%
0.0620924
0.00125s
0.16%
0.0569211
0.00296s
0.17%
0.0517171
0.00203s
0.17%
0.043252
0.00328s
0.18%
0.0422427
0.00203s
0.19%
0.0392169
10 0.00062s
0.2%
0.0422221
0.00093s
0.21%
0.0368006
0.00171s
0.22%
0.0347552
0.00203s
0.22%
0.0379786
0.00203s
0.23%
0.031969
0.00125s
0.24%
0.0330868
0.00125s
0.24%
0.0297968
0.00093s
0.25%
0.0310117
0.0014s
0.25%
0.0297494
0.00203s
0.26%
0.0294368
20 0.00265s
0.26%
0.0293309
0.00125s
0.27%
0.029215
0.00156s
0.27%
0.0303057
0.0014s
0.28%
0.0288256
0.00171s
0.28%
0.0282171
0.00234s
0.29%
0.0283723
0.00265s
0.29%
0.028685
0.00203s
0.3%
0.0272425
0.00156s
0.3%
0.0285963
0.00187s
0.31%
0.0272064
30 0.00109s
0.31%
0.0276539
0.00125s
0.31%
0.0267576
0.00171s
0.32%
0.0263787
0.00218s
0.32%
0.0261323
0.00281s
0.33%
0.0259851
0.00265s
0.33%
0.0255105
0.00171s
0.34%
0.0257426
0.00218s
0.34%
0.0256904
0.0014s
0.35%
0.0244036
0.00109s
0.35%
0.0240638
40 0.00203s
0.35%
0.0237804
0.0025s
0.36%
0.0238457
0.00171s
0.37%
0.0238859
0.00234s
0.37%
0.0237965
0.0014s
0.37%
0.0235585
0.00312s
0.38%
0.0235125
0.00234s
0.38%
0.0230809
0.0025s
0.38%
0.0230794
0.00281s
0.39%
0.0230247
0.00218s
0.4%
0.0229079
50 0.00281s
0.4%
0.0229053
0.0014s
0.4%
0.0225968
0.00156s
0.4%
0.0226454
0.00125s
0.41%
0.0226777
0.00125s
0.41%
0.0225282
0.00187s
0.41%
0.022356
0.00093s
0.42%
0.0222671
0.00125s
0.42%
0.022248
0.00109s
0.42%
0.0219874
0.00203s
0.43%
0.0219296
60 0.00234s
0.43%
0.0216264
0.00203s
0.44%
0.0218879
0.00343s
0.44%
0.0218768
0.00234s
0.45%
0.0218769
0.00203s
0.45%
0.0212353
0.00296s
0.46%
0.0210564
0.00281s
0.46%
0.0209537
0.00203s
0.47%
0.0210161
0.00312s
0.48%
0.02071
0.00234s
0.48%
0.02074
70 0.00109s
0.49%
0.0208624
0.00187s
0.5%
0.0211692
0.0014s
0.51%
0.0210033
0.00156s
0.52%
0.0203721
0.0014s
0.53%
0.0199919
0.00234s
0.53%
0.0199126
0.00203s
0.54%
0.0196769
0.00093s
0.56%
0.0195759
0.00359s
0.57%
0.0195187
0.00375s
0.58%
0.0188534
80 0.005s
0.59%
0.0187775
0.00421s
0.61%
0.0186276
0.00421s
0.62%
0.0185397
0.00515s
0.64%
0.0186122
0.00468s
0.66%
0.018561
0.00531s
0.68%
0.0181595
0.00375s
0.7%
0.0182148
0.00406s
0.72%
0.0179561
0.0039s
0.74%
0.0178322
0.00468s
0.76%
0.0177949
90 0.00609s
1.16%
0.0056149
0.0064s
1.21%
0.00525581
0.00562s
1.26%
0.0049451
0.00609s
1.33%
0.00456451
0.00812s
1.42%
0.00415819
0.00531s
1.52%
0.00377525
0.0064s
1.66%
0.0033616
0.0064s
1.82%
0.00299557
0.00656s
2.03%
0.00261352
0.00515s
2.38%
0.00229963

As for the photo, my rule-of-thumb "less than 1% difference" is achieved for quality levels at or above 90. If we tolerate a 2% difference, we need to specify a quality of 46 or above.

JPG compression is not suited to graphics. It makes smooth colours rougher, and introduces ringing at edges.

Summary

We summarise the findings for this photograph and graphic.

cPrefix /p0 /iph_summ.csv /t"Format,Option,Time,Compression,Difference"
cSort   /p0 /iph_summ.csv /oph_summ.csv /h /kTime
call csv2tab ph_summ
Format Option Time Compression Difference
miff -compress None 0.2844 100 0
jpg -quality 01 0.3 0.12 0.0661949
tiff -compress None 0.353 100.03 0
miff -compress Zip -quality 01 1.05 100.050 0
mpc -compress None 2.7346 133.33 0
png -quality 02 3.1876 97.79 0
tiff -compress Zip -quality 01 4.0312 100.02 0

For this photograph, the fastest methods are uncompressed MPC, MIFF and TIFF. Low-quality JPG is also fast but the quality is horrible.

The fastest PNG hardly saves any space compare to TIFF with no compression, and takes ten times as long. PNG is not recommended, except for output to web pages that require no loss (making JPG unsuitable).

cPrefix /p0 /igr_summ.csv /t"Format,Option,Time,Compression,Difference"
cSort   /p0 /igr_summ.csv /ogr_summ.csv /h /kTime
call csv2tab gr_summ
Format Option Time Compression Difference
mpc -compress None 0.00047 133.33 0
jpg -quality 10 0.00062 0.2 0.0422221
miff -compress None 0.00281 100.06 0
png -quality 23 0.00641 1.31 0
miff -compress Zip -quality 20 0.00797 1.98 0
tiff -compress Zip -quality 30 0.01875 1.56 0
tiff -compress None 0.03157 100.13 0

For this graphic, the fastest methods are uncompressed MPC and MIFF. The fastest "portable" format is PNG, -quality 10.

Conclusions

I am interested only in lossless compression.

For writing photographic images:

For writing graphic images:

Scripts

For convenience, .bat scripts are also available in a single zip file. See Zipped BAT files.

The scripts use ls and stat, as provided by Cygwin. They also use my own timecc.exe, cProject.exe and cEcho.exe. I don't publish source or executables of these.

compSpd.bat

rem Speeds of writing compressed outputs.

@rem %1 is input image file.
@rem %2 is prefix for output data files.
@rem %3 is output sufix, eg png, tiff, jpg.
@rem %4 is number of times to execute command [default 1].
@rem %5 is output summary list.


set INFILE=%1

set OUT_PREFIX=%2
if "%OUT_PREFIX%"=="" set OUT_PREFIX=ts

set EXT=%3
if "%EXT%"=="" set EXT=tiff

set N_TIMES=%4
if "%N_TIMES%"=="" set N_TIMES=1

set BASE_CMD=%IM%convert %INFILE% -quiet

set DATA_EXT=%EXT%
if /i "%DATA_EXT%"=="mpc" set DATA_EXT=cache

set OUTFILE=%OUT_PREFIX%_cs.%EXT%
set DATAFILE=%OUT_PREFIX%_cs.%DATA_EXT%

set SUM_LIST=
if not "%5"=="" set SUM_LIST=%5


for /F "usebackq" %%B in (`timecc ^
  /n%N_TIMES% /f"\t" ^
  /c"%BASE_CMD% -compress None NULL:"`) do set BASE_TIME=%%B

echo BASE_TIME=%BASE_TIME%

echo -compress,Seconds,Compression %%,Difference >%OUT_PREFIX%.csv

rem FIXME: also do one with no "-compress" setting.

for /F "usebackq" %%C in (`%IM%convert -list compress`) do (
  echo %%C

  del %OUTFILE% >nul

  rem timecc ^
  rem   /n%N_TIMES% /f"%%C,\t," ^
  rem   /O%OUT_PREFIX%.csv /b%BASE_TIME% ^
  rem   /c"%BASE_CMD% -compress %%C %OUTFILE%"

  for /F "usebackq" %%T in (`timecc ^
    /n%N_TIMES% /f"\t" ^
    /o- /b%BASE_TIME% ^
    /c"%BASE_CMD% -compress %%C %OUTFILE%"`) do set TIME=%%T

  if exist %OUTFILE% (

    for /F "usebackq tokens=2 delims=() " %%D in (`%IM%compare ^
      -quiet -metric RMSE %INFILE% %OUTFILE% NULL: 2^>^&1`) do set DIFF=%%D

    for /F "usebackq" %%B in (`stat --printf=%%s %DATAFILE%`) do set BYTES=%%B
    echo BYTES=%BYTES%

    for /F "usebackq" %%C in (`%IM%identify ^
      -ping ^
      -format "%%[fx:int(!BYTES!*100/w/h/6*100+0.5)/100]" ^
      %OUTFILE%`) do set COMPR=%%C

    cEcho /O%OUT_PREFIX%.csv /X /s"%%C,!TIME!s,!COMPR!%%,!DIFF!"

    if not "%SUM_LIST%"=="" if /I "%%C"=="None" cEcho /O%SUM_LIST% /s"%EXT%,-compress None,!TIME!,!COMPR!,!DIFF!"

  ) else (
    echo No output file >>%OUT_PREFIX%.csv
  )
)

del %OUTFILE% >nul
del %DATAFILE% >nul

type %OUT_PREFIX%.csv

call csv2tab %OUT_PREFIX%

qual99Spd.bat

rem Speeds of writing outputs with quality 00 to 99.
rem Also measures size of output files, in bytes.
rem For TIFF and MIFF, tests just 00, 01, 10, 11, 20, 21 etc.
rem For JPG format, also measures difference from input image.
rem Writes output in HTML table format.

@rem %1 is input image file.
@rem %2 is prefix for output data files.
@rem %3 is output sufix, eg png, tiff, jpg.
@rem %4 is number of times to execute command [default 1].
@rem %5 is output summary list.

@rem Updated:
@rem   26-September-2016  Bug in comparison fixed.


set INFILE=%1

set OUT_PREFIX=%2
if "%OUT_PREFIX%"=="" set OUT_PREFIX=q9s

set EXT=%3
if "%EXT%"=="" set EXT=tiff

set N_TIMES=%4
if "%N_TIMES%"=="" set N_TIMES=1

set SUM_LIST=
if not "%5"=="" set SUM_LIST=%5

set DO_DIFF=0
if /i %EXT%==jpg set DO_DIFF=1
if /i %EXT%==jpeg set DO_DIFF=1

set OUTFILE=%OUT_PREFIX%_q9s.%EXT%
set TIME_FILE=%OUT_PREFIX%_q9s.lis
del %TIME_FILE% >nul
set TMP_LST=%OUT_PREFIX%_q9s_c.csv
del %TMP_LST% >nul

set COMP=
if /i %EXT%==miff set COMP=-compress Zip
if /i %EXT%==tiff set COMP=-compress Zip
if /i %EXT%==tif set COMP=-compress Zip

if "%COMP%"=="" (
  set MAX_J=9
) else (
  set MAX_J=1
)

set BASE_CMD=%IM%convert %INFILE% -quiet %COMP%

for /F "usebackq" %%B in (`timecc ^
  /n%N_TIMES% /f"\t" ^
  /f"\t" /c"%BASE_CMD% -quality 0 NULL:"`) do set BASE_TIME=%%B

echo BASE_TIME=%BASE_TIME%

set DIFF=
del %OUT_PREFIX%.csv >nul

if %MAX_J%==9 (
  cEcho /O%OUT_PREFIX%.csv /f\r\n /s"-quality,0,1,2,3,4,5,6,7,8,9"
) else (
  cEcho /O%OUT_PREFIX%.csv /f\r\n /s"-quality,0,1..9"
)

for /L %%i in (0,1,9) do (
  cEcho /O%OUT_PREFIX%.csv /f\r /s%%i0,
  for /L %%j in (0,1,%MAX_J%) do (

    for /F "usebackq" %%T in (`timecc ^
      /n%N_TIMES% /f"\t" ^
      /o- /b%BASE_TIME% ^
      /c"%BASE_CMD% -quality %%i%%j %OUTFILE%"`) do set TIME=%%T

    for /F "usebackq" %%B in (`stat --printf=%%s %OUTFILE%`) do set BYTES=%%B

    for /F "usebackq" %%C in (`%IM%identify ^
      -ping ^
      -format "%%[fx:int(!BYTES!*100/w/h/6*100+0.5)/100]" ^
      %OUTFILE%`) do set COMPR=%%C

    set nDIFF=0
    set sDIFF=

    if %DO_DIFF%==1 (
      for /F "usebackq tokens=2 delims=() " %%D in (`%IM%compare ^
        -quiet -metric RMSE %INFILE% %OUTFILE% NULL: 2^>^&1`) do set nDIFF=%%D

      set sDIFF=\^(br /\^)!nDIFF!
    )

    echo TIME=!TIME! BYTES=!BYTES! COMPR=!COMPR! nDIFF=!nDIFF!

    echo !TIME! >>%TIME_FILE%

    if %%j==%MAX_J% (
      cEcho /O%OUT_PREFIX%.csv /X /f\r /s"!TIME!s\^(br /\^)!COMPR!%%!sDIFF!\n"
    ) else (
      cEcho /O%OUT_PREFIX%.csv /X /f\r /s"!TIME!s\^(br /\^)!COMPR!%%!sDIFF!,"
    )

    cEcho /O%TMP_LST% /s"%EXT%,%COMP% -quality %%i%%j,!TIME!,!COMPR!,!nDIFF!"
  )
)

echo BASE_TIME=%BASE_TIME%

call csv2tab %OUT_PREFIX%

del %OUTFILE% >nul

type %TIME_FILE%

for /F "usebackq" %%T in (`cSort ^
  /p0 /k0 /i%TIME_FILE% /o- ^| cHead /p0 /i- /h1 /o-`) do set MIN_TIME=%%T

echo MIN_TIME=%MIN_TIME%

chStrs /i%OUT_PREFIX%.htm /o%OUT_PREFIX%.htm /f\(td\)%MIN_TIME% /t"\(td class=\"good\"\)%MIN_TIME%"

cSort /i%TMP_LST% /o- /k2 | cHead /i- /h1 /O%SUM_LIST%

All images on this page were created by the commands shown, using:

%IM%identify -version
Version: ImageMagick 6.9.5-3 Q16 x86 2016-07-22 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC Modules OpenMP 
Delegates (built-in): bzlib cairo flif freetype jng jp2 jpeg lcms lqr openexr pangocairo png ps rsvg tiff webp xml zlib

Source file for this web page is spdsiz.h1. To re-create this web page, execute "procH1 spdsiz".


This page, including the images, is my copyright. Anyone is permitted to use or adapt any of the code, scripts or images for any purpose, including commercial use.

Anyone is permitted to re-publish this page, but only for non-commercial use.

Anyone is permitted to link to this page, including for commercial use.


Page version v1.0 1-Jun-2015.

Page created 27-Sep-2016 21:56:09.

Copyright © 2016 Alan Gibson.