Skip to main content
naming; removed thanks
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

Converting a GeotiffGeoTIFF image from RGB to gray scale using Rasterio or GDAL in pythonPython

I was using PIL to convert some images from RGB to gray scale in pythonPython, 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. Thanks.

Converting a Geotiff image from RGB to gray scale using Rasterio or GDAL in python

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. Thanks.

Converting a GeoTIFF image from RGB to gray scale using Rasterio or GDAL in Python

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.

Source Link
krishnab
  • 929
  • 2
  • 14
  • 24

Converting a Geotiff image from RGB to gray scale using Rasterio or GDAL in python

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. Thanks.