I was using PIL
to convert some images from RGB to gray scale in Python, but this code does not work well for GeoTIFF files. It seems that PIL
does not seem to work with with GeoTIFF files in particular.
I was using the code:
from PIL import Image
t = Image.open('testfile.tif')
gray_image = image.convert('L')
So I was wondering if there is a way to load an image in say rasterio
and then convert it to a gray scale array. Now I could manually do this by writing a simple function to matrix multiply the image array, BUT the files are pretty large and so I run into memory issues. So I would likely need to do a windowed read on the file.
If there is a convenience function in rasterio
or GDAL
for this, could someone point it out. I searched but could not find anything. Otherwise I can try to work on creating a windowed read.
PIL
utility seems to handle converting to grayscale without blowing up the memory, so I imagine it already implements a windowed read, though I am not sure. I was just wondering ifrasterio
orGDAL
provide a similar functionality. I can write windows myself, but was wondering whether I needed to or not.block_windows()
should only take an extra a line or two of codeblocks_windows()
over the output array for the gray scale image, haha. I found that trying to preallocate a (31833, 39197) float64 array did not go very well.blocks_windows()
returns when you go to write the output image, no need to pre-create the output or iterate over anything separately