Can you skip pixels in an image without loading the entire image?

I have very large images. I don’t want to load the whole image into memory, I just want to make one pass through the image in row order. Is it possible to do this in Python / scipy?

EDIT: I use .PNG, but I can convert them to PPM, BMP or something else without loss.

+5
source share
1 answer

GDAL (with Python bindings) offers some very good drivers for this. Although it is a geospatial data package, it works great with BMP and PNG, for example. This example shows how to load PNG line by line:

import gdal

# only loads the dataset
ds = gdal.Open('D:\\my_large_image.png')

# read 1 row at the time
for row in range(ds.RasterYSize):
    row_data = ds.ReadAsArray(0,row,ds.RasterXSize,1)

ds = None # this closes the file

Numpy, . .

print type(row_data)
<type 'numpy.ndarray'>

print row_data.shape
(3, 1, 763)

print row_data
[[[  0   0 255 ..., 230 230   0]]

 [[  0   0 252 ..., 232 233   0]]

 [[  0   0 252 ..., 232 233   0]]]

, , , PIL - . , 30000 * 30000 , .

+2

All Articles