Skip to content

Commit 22fb6ca

Browse files
committed
updates
- use strip tiff everywhere - vips progs all use reduce - pillow uses bilinear
1 parent 39f0310 commit 22fb6ca

File tree

11 files changed

+52
-117
lines changed

11 files changed

+52
-117
lines changed

benchmark.sh

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ mkdir $tmp
99

1010
echo building test image ...
1111
vips colourspace sample2.v $tmp/t1.v srgb
12-
vips colourspace sample2.v $tmp/t1.v srgb
1312
vips replicate $tmp/t1.v $tmp/t2.v 20 15
14-
vips extract_area $tmp/t2.v $tmp/x.tif[tile] 0 0 5000 5000
15-
vips copy $tmp/x.tif $tmp/x_strip.tif
13+
vips extract_area $tmp/t2.v $tmp/x.tif 0 0 5000 5000
1614
vips copy $tmp/x.tif $tmp/x.jpg
1715
vips copy $tmp/x.tif $tmp/x.ppm
1816
vipsheader $tmp/x.tif
@@ -28,7 +26,7 @@ real_time() {
2826
# get just the "real 0.2" line
2927
real=($(cat tmp/x | grep real))
3028

31-
# just the the number
29+
# and just the number
3230
return_real_time=${real[1]}
3331
}
3432

@@ -37,7 +35,7 @@ real_time() {
3735
# sleep for two secs between runs to let the system settle -- after a run
3836
# there's a short period of disc chatter we want to avoid
3937

40-
# check that services like tracker are not running
38+
# you should check that services like tracker are not running
4139

4240
get_time() {
4341
cmd=$*
@@ -89,12 +87,11 @@ echo "program, time (s), peak memory (MB)"
8987

9088
benchmark tiffcp "tiffcp -s $tmp/x.tif $tmp/x2.tif"
9189

90+
benchmark pillow "./pillow.py $tmp/x.tif $tmp/x2.tif"
91+
9292
gcc -Wall vips.c `pkg-config vips --cflags --libs` -o vips-c
9393
benchmark vips-c "./vips-c $tmp/x.tif $tmp/x2.tif"
9494

95-
echo -n strip-
96-
benchmark vips-c "./vips-c $tmp/x_strip.tif $tmp/x2.tif"
97-
9895
gcc -Wall vips.c `pkg-config vips --cflags --libs` -o vips-c
9996
echo -n ppm-
10097
benchmark vips-c "./vips-c $tmp/x.ppm $tmp/x2.ppm"
@@ -103,21 +100,23 @@ benchmark vips.lua "./vips.lua $tmp/x.tif $tmp/x2.tif"
103100

104101
benchmark vips.php "./vips.php $tmp/x.tif $tmp/x2.tif"
105102

106-
benchmark vips8-gegl.py "./vips8-gegl.py $tmp/x.tif $tmp/x2.tif"
103+
benchmark vips-gegl.py "./vips-gegl.py $tmp/x.tif $tmp/x2.tif"
107104

108-
g++ vips8.cc `pkg-config vips-cpp --cflags --libs` -o vips8-cc
109-
benchmark vips8-cc "./vips8-cc $tmp/x.tif $tmp/x2.tif"
105+
g++ vips.cc `pkg-config vips-cpp --cflags --libs` -o vips-cc
106+
benchmark vips-cc "./vips-cc $tmp/x.tif $tmp/x2.tif"
110107

111108
benchmark vips.js "./vips.js $tmp/x.tif $tmp/x2.tif"
112109

113-
benchmark pyvips2.py "./pyvips2.py $tmp/x.tif $tmp/x2.tif"
110+
benchmark pyvips-bench.py "./pyvips-bench.py $tmp/x.tif $tmp/x2.tif"
114111

115112
benchmark ruby-vips "./ruby-vips.rb $tmp/x.tif $tmp/x2.tif"
116113

117114
gcc -Wall vips.c `pkg-config vips --cflags --libs` -o vips-c
118115
echo -n jpg-
119116
benchmark vips-c "./vips-c $tmp/x.jpg $tmp/x2.jpg"
120117

118+
benchmark pillow "./pillow.py $tmp/x.tif $tmp/x2.tif"
119+
121120
benchmark vips "./vips.sh $tmp/x.tif $tmp/x2.tif"
122121

123122
echo -n ppm-
@@ -133,7 +132,7 @@ benchmark nip2 "./vips.nip2 $tmp/x.tif -o $tmp/x2.tif"
133132
# OS X only
134133
# benchmark sips "./sips.sh $tmp/x.tif $tmp/x2.tif"
135134

136-
benchmark pnm "./netpbm.sh $tmp/x_strip.tif $tmp/x2.tif"
135+
benchmark pnm "./netpbm.sh $tmp/x.tif $tmp/x2.tif"
137136

138137
benchmark rmagick "./rmagick.rb $tmp/x.tif $tmp/x2.tif"
139138

@@ -143,13 +142,6 @@ echo -n 1thread-
143142
benchmark vips-c "./vips-c $tmp/x.tif $tmp/x2.tif"
144143
unset VIPS_CONCURRENCY
145144

146-
# tried pillow-simd with
147-
# CC="cc -O3 -march=native" pip install --user --force-reinstall \
148-
# --ignore-installed --no-binary :all: pillow-simd
149-
# but no faster ... presumably most time is being spent elsewhere
150-
# tried with resize LANCZOS, pillow-simd helps a lot
151-
benchmark pillow "./pillow.py $tmp/x.tif $tmp/x2.tif"
152-
153145
# this needs careful config, see
154146
# https://github.com/jcupitt/vips-bench/issues/4
155147
YMAGINE=/home/john/ymagine
@@ -169,7 +161,7 @@ benchmark opencv "./opencv $tmp/x.tif $tmp/x2.tif"
169161

170162
benchmark convert "./im.sh $tmp/x.tif $tmp/x2.tif"
171163

172-
benchmark econvert "./ei.sh $tmp/x_strip.tif $tmp/x2.tif"
164+
benchmark econvert "./ei.sh $tmp/x.tif $tmp/x2.tif"
173165

174166
echo -n jpg-
175167
benchmark convert "./im.sh $tmp/x.jpg $tmp/x2.jpg"
@@ -192,13 +184,12 @@ benchmark gd "./gd $tmp/x.jpg $tmp/x2.jpg"
192184

193185
benchmark oiio "./oiio.sh $tmp/x.tif $tmp/x2.tif"
194186

195-
benchmark imagej "imagej -x 1000 -i tmp/x_strip.tif -b bench.ijm"
187+
benchmark imagej "imagej -x 1000 -i tmp/x.tif -b bench.ijm"
196188

197189
gcc -Wall gegl.c `pkg-config gegl-0.3 --cflags --libs` -o gegl
198-
echo -n tiff-
199-
benchmark gegl "./gegl $tmp/x.tif $tmp/x2.tif"
200-
echo -n strip-tiff-
201-
benchmark gegl "./gegl $tmp/x_strip.tif $tmp/x2.tif"
190+
# gegl-0.3 doesn't have tiff support built in
191+
# echo -n tiff-
192+
# benchmark gegl "./gegl $tmp/x.tif $tmp/x2.tif"
202193
echo -n jpg-
203194
benchmark gegl "./gegl $tmp/x.jpg $tmp/x2.jpg"
204195

pillow.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,15 @@
44
from PIL import Image, ImageFilter, PILLOW_VERSION
55

66
# just to confirm we are getting the right version
7-
# print("pillow.py: PILLOW_VERSION =", PILLOW_VERSION)
7+
# print 'pillow.py: PILLOW_VERSION =', PILLOW_VERSION
88

99
im = Image.open(sys.argv[1])
1010

1111
# Crop 100 pixels off all edges.
12-
im = im.crop((100, 100, im.size[0] - 100, im.size[1] - 100))
12+
im = im.crop((100, 100, im.width - 100, im.height - 100))
1313

1414
# Shrink by 10%
15-
16-
# starting with 2.7, Pillow uses a high-quality convolution-based resize for
17-
# BILINEAR ... the other systems in this benchmark are using affine + bilinear,
18-
# so this is rather unfair. Use NEAREST instead, it gets closest to what
19-
# everyone else is doing
20-
21-
# pillow-simd reduces the LANCZOS time down to only 10% more than NEAREST
22-
23-
im = im.resize((int (im.size[0] * 0.9), int (im.size[1] * 0.9)),
24-
# Image.LANCZOS)
25-
Image.NEAREST)
15+
im = im.resize((int(im.width * 0.9), int(im.height * 0.9)), Image.BILINEAR)
2616

2717
# sharpen
2818
filter = ImageFilter.Kernel((3, 3),

pyvips2.py renamed to pyvips-bench.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import sys
44
import pyvips
55

6-
im = pyvips.Image.new_from_file(sys.argv[1])
6+
im = pyvips.Image.new_from_file(sys.argv[1], access='sequential')
77

88
im = im.crop(100, 100, im.width - 200, im.height - 200)
99
im = im.similarity(scale = 0.9,
10-
interpolate = pyvips.Interpolate.new("bilinear"))
10+
interpolate = pyvips.Interpolate.new('bilinear'))
1111
mask = pyvips.Image.new_from_array([[-1, -1, -1],
1212
[-1, 16, -1],
13-
[-1, -1, -1]], scale = 8)
14-
im = im.conv(mask, precision = "integer")
13+
[-1, -1, -1]], scale=8)
14+
im = im.conv(mask, precision='integer')
1515

1616
im.write_to_file(sys.argv[2])

vips-gegl.py

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,21 @@
11
#!/usr/bin/python
22

33
import sys
4-
from vipsCC import *
4+
import pyvips
55

6-
im = VImage.VImage (sys.argv[1])
6+
im = pyvips.Image.new_from_file(sys.argv[1], access='sequential')
77

8-
# add an all-255 alpha
9-
alpha = VImage.VImage.black (1, 1, 1).lin (1, 255)
10-
alpha = alpha.clip2fmt (VImage.VImage.FMTUCHAR)
11-
alpha = alpha.embed (1, 0, 0, im.Xsize (), im.Ysize ())
12-
im = im.bandjoin (alpha)
8+
im = im.bandjoin(255)
9+
im = im.colourspace('scrgb')
1310

14-
# turn to linear float 0 - 1
15-
gamma = 2.4
16-
lut = VImage.VImage.identity (1)
17-
lut = lut.pow (1.0 / gamma)
18-
lut = lut.lin (1.0 / pow (255, 1.0 / 2.4), 0)
19-
im = im.maplut (lut)
11+
im = im.crop(100, 100, im.width - 200, im.height - 200)
12+
im = im.reduce(1.0 / 0.9, 1.0 / 0.9, kernel='linear')
13+
mask = pyvips.Image.new_from_array([[-1, -1, -1],
14+
[-1, 16, -1],
15+
[-1, -1, -1]], scale=8)
16+
im = im.conv(mask, precision='integer')
2017

21-
im = im.extract_area (100, 100, im.Xsize () - 200, im.Ysize () - 200)
18+
im = im.colourspace('srgb')
19+
im = im.extract_band(0, n=3)
2220

23-
im = im.affine (0.9, 0, 0, 0.9, 0, 0, 0, 0,
24-
int (im.Xsize() * 0.9), int (im.Ysize() * 0.9))
25-
26-
mask = VMask.VIMask (3, 3, 8, 0,
27-
[-1, -1, -1,
28-
-1, 16, -1,
29-
-1, -1, -1])
30-
im = im.conv (mask)
31-
32-
# back to non-linear 0 - 65535
33-
im = im.lin (65535, 0)
34-
# im = im.pow (2.4)
35-
36-
# back to uint16
37-
im = im.clip2fmt (VImage.VImage.FMTUSHORT)
38-
39-
im.write (sys.argv[2])
21+
im.write_to_file(sys.argv[2])

vips.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ main( int argc, char **argv )
1515
global = vips_image_new();
1616
t = (VipsImage **) vips_object_local_array( VIPS_OBJECT( global ), 5 );
1717

18-
VipsInterpolate *interp = vips_interpolate_new( "bilinear" );
19-
20-
if( !(t[0] = vips_image_new_from_file( argv[1], NULL )) )
18+
if( !(t[0] = vips_image_new_from_file( argv[1],
19+
"access", VIPS_ACCESS_SEQUENTIAL, NULL )) )
2120
vips_error_exit( NULL );
2221

2322
t[1] = vips_image_new_matrixv( 3, 3,
@@ -26,18 +25,15 @@ main( int argc, char **argv )
2625
-1.0, -1.0, -1.0 );
2726
vips_image_set_double( t[1], "scale", 8 );
2827

29-
if( vips_extract_area( t[0], &t[2],
28+
if( vips_crop( t[0], &t[2],
3029
100, 100, t[0]->Xsize - 200, t[0]->Ysize - 200, NULL ) ||
3130
/* lanczos2 version, handy for testing against pillow
3231
vips_reduce( t[2], &t[3], 1.0 / 0.9, 1.0 / 0.9,
3332
"kernel", VIPS_KERNEL_LANCZOS2,
3433
NULL ) ||
3534
*/
36-
/* bilinear, matching the other progs here
37-
*/
38-
vips_similarity( t[2], &t[3],
39-
"scale", 0.9,
40-
"interpolate", interp,
35+
vips_reduce( t[2], &t[3], 1.0 / 0.9, 1.0 / 0.9,
36+
"kernel", VIPS_KERNEL_LINEAR,
4137
NULL ) ||
4238
vips_conv( t[3], &t[4], t[1],
4339
"precision", VIPS_PRECISION_INTEGER,
@@ -46,7 +42,6 @@ main( int argc, char **argv )
4642
vips_error_exit( NULL );
4743

4844
g_object_unref( global );
49-
g_object_unref( interp );
5045

5146
return( 0 );
5247
}

vips8.cc renamed to vips.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// compile with
2-
// g++ vips8.cc `pkg-config vips-cpp --cflags --libs`
2+
// g++ vips.cc `pkg-config vips-cpp --cflags --libs`
33

44
#include <vips/vips8>
55

@@ -28,19 +28,17 @@ main( int argc, char **argv )
2828
}
2929
g_option_context_free( context );
3030

31-
VImage in = VImage::new_from_file( argv[1] );
31+
VImage in = VImage::new_from_file( argv[1],
32+
VImage::option()-> set( "access", VIPS_ACCESS_SEQUENTIAL ));
3233

3334
VImage mask = VImage::new_matrixv( 3, 3,
3435
-1, -1, -1, -1, 16, -1, -1, -1, -1 );
3536
mask.set( "scale", 8 );
3637

37-
VInterpolate inter = VInterpolate::new_from_name( "bilinear" );
38-
3938
in.
4039
extract_area( 100, 100, in.width() - 200, in.height() - 200 ).
41-
similarity( VImage::option()->
42-
set( "scale", 0.9 )->
43-
set( "interpolate", inter ) ).
40+
reduce( 1.0 / 0.9, 1.0 / 0.9, VImage::option()->
41+
set( "kernel", VIPS_KERNEL_LINEAR ) ).
4442
conv( mask, VImage::option()->
4543
set( "precision", VIPS_PRECISION_INTEGER )).
4644
write_to_file( argv[2] );

vips.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
var vips = require('../node-vips');
44

5-
image = vips.Image.newFromFile(process.argv[2]);
5+
image = vips.Image.newFromFile(process.argv[2], {access: 'sequential'});
6+
67
image = image.crop(100, 100, image.width - 200, image.height - 200);
78

89
image = image.reduce(1.0 / 0.9, 1.0 / 0.9, {kernel: 'linear'});

vips.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
local vips = require("vips")
44

5-
image = vips.Image.new_from_file(arg[1])
5+
image = vips.Image.new_from_file(arg[1], {access = "sequential"})
66

77
image = image:crop(100, 100, image:width() - 200, image:height() - 200)
88

vips.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use Jcupitt\Vips;
77

8-
$im = Vips\Image::newFromFile($argv[1]);
8+
$im = Vips\Image::newFromFile($argv[1], ["access" => "sequential"]);
99

1010
$im = $im->crop(100, 100, $im->width - 200, $im->height - 200);
1111

vips.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ height=$((height - 200))
99
# set -x
1010

1111
vips crop $1 t1.v 100 100 $width $height
12-
vips similarity t1.v t2.v --scale 0.9 --interpolate bilinear
12+
vips reduce t1.v t2.v 1.111 1.111 --kernel linear
1313

1414
cat > mask.con <<EOF
1515
3 3 8 0

0 commit comments

Comments
 (0)