Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resize a large image that does not fit into memory

I have a large GeoTiff (let`s say 200,000 by 200,000 pixels) that I need to resize using, for example, opencv or gdal. The problem I am facing is that I cannot load the entire image into memory, so something like:

data_out = cv2.resize(data_in, dsize=dsize, interpolation=cv2.INTER_AREA)

is not doable. I thought to tile (or read) the large image into several smaller images (with their own geo-information) so that I can resized each of them individually and then mosaic them back together. However, this approach seems to suffer at the edges, creating discontinuities across the mosaiced output.

Is there any way I can resize the large image without loading the whole data into memory?

like image 686
Knulph Avatar asked Sep 02 '25 14:09

Knulph


1 Answers

As Goyo has already commented, you can use gdalwarp to resample the image. If you are a Mac or Linux user, you can run gdalwarp directly from the command line:

gdalwarp -of GTiff -co COMPRESS=DEFLATE -ts 20000 20000 -r cubic InputImage.tif OutputImage.tif

The -ts option allows you to specify the target size of the output raster (width, height).

gdalwarp has several resampling methods, but the cubic or bilinear algorithms are the most widely used within the remote sensing and GIS community.