Repository for Ideas & Research
Open Source GIS, Hydrologic Modeling, Optimization

How to convert a color raster dataset to grayscale using ArcPy

import numpy as np

filename = r'p:\raster.tif'

# read a raster dataset
rast = arcpy.Raster(filename)

# convert the raster into an array
rast_array = arcpy.RasterToNumPyArray(rast)

# create a single-band grayscale raster
gray_array = rast_array[0] * 0.299 + rast_array[1] * 0.587 + rast_array[2] * 0.114

# convert the grayscale array to a raster
gray_rast = arcpy.NumPyArrayToRaster(gray_array, rast.extent.lowerLeft, rast.meanCellWidth, rast.meanCellHeight)