1

I have a TIFF file with a size of (48000, 432000) and I would like to upload only a piece of the image, for example, pass a parameter like (X, Y, wid, hei), where X, Y are the coordinates of the upper-left corner of the piece, and wid, hei are the width and height of the piece, respectively. Because if you upload the entire image, a memory error will inevitably occur.

I read this post, looked at the tifffile library documentation, I tried to find a similar method in PIL, but I did not find a similar solution.

Maybe someone can tell me how you can load a piece of an image into RAM in this way?

3
  • 3
    What was the problem when you tried to applied the solutions shown in the other question you have linked? Commented Oct 20 at 7:01
  • 5
    By "upload" do you simply mean "load from file into memory" or something else? Commented Oct 20 at 7:02
  • mkrieger1 I'm trying to load it into RAM, right. There is an action that is performed literally with one line of code, so I did not apply it. Commented Oct 20 at 10:32

1 Answer 1

2

You could try rasterio's "windowed reading" functionalities:

From the docs (https://rasterio.readthedocs.io/en/latest/topics/windowed-rw.html):

Beginning in rasterio 0.3, you can read and write “windows” of raster files. This feature allows you to work on rasters that are larger than your computers RAM or process chunks of large rasters in parallel.

Here is an example of reading a 256 row x 512 column subset of the rasterio test file.

import rasterio
from rasterio.windows import Window

with rasterio.open('tests/data/RGB.byte.tif') as src:
    w = src.read(1, window=Window(0, 0, 512, 256))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.