Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the fastest way to slice an image into tiles?

I need to slice an image (size: 14043 × 9933) into 256 x 256 set of tiles with different zoom levels (number of tiles) in the most efficient way. I've been using gdal2tiles.py(it comes with GDAL), but I wonder if there's other options out there, maybe Geotools have this functionality? or any other alternatives (I don't need and and geo-referencing to the tiles).

Thanks in advance.

like image 429
ddayan Avatar asked Dec 05 '25 00:12

ddayan


1 Answers

gdal2tiles is a nice thing and can do many projections, but it's slow for simple raster tile pyramids and needs a lot of memory. dzsave is faster and more efficient with RAM. On this laptop with a 25k x 25k RGB JPG file I see:

$ time gdal2tiles.py -p raster ../wac_nearside.jpg x
Generating Base Tiles:
0...10...20...30...40...50...60...70...80...90...100 - done.
Generating Overview Tiles:
0...10...20...30...40...50...60...70...80...90...100 - done.
real    3m51.728s
user    3m48.548s
sys 0m2.992s
peak memory 400mb

But with dzsave I see:

$ time vips dzsave ../wac_nearside.jpg y --suffix .png
real    0m36.097s
user    1m39.900s
sys 0m6.960s
peak memory 100mb

It would be faster still, but almost all the time is being spent in PNG write. If I drop back to the default JPEG tiles I see:

$ time vips dzsave ../wac_nearside.jpg y
real    0m10.791s
user    0m20.268s
sys 0m4.672s
peak memory 100mb

More than 20x faster than gdal2tiles.

dzsave can also do the centring for you automatically, so there's no need for the extra gdal_translate step.

like image 63
jcupitt Avatar answered Dec 06 '25 16:12

jcupitt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!