While I am always interested in remote sensing, my focus has been on GIS/GPS data and applications, largely due to the nature of my day-to-day routines at work which include GIS analysis and map production using almost exclusively vector data.
Working with Google Earth the other day, I wondered how easy it would be to select an area of a raster image based on certain color, i.e. to select or identify features characterized by certain color ranges of each raster bands. A simple quality control measure would be a comparison of the raster selection with a shapefile with point data for a few sample features.
Since I don’t have a Spatial Analyst license, I tried to attack this with only ArcView…
Find a raster file and add individual bands as separate layers to your map. In my case, this was a (more or less random) 6BM (approx. 3000x2000px) GeoTIFF with 3 bands.
Find the color range in each band that is typical for the type of feature. – By default, one-band rasters will be displayed as grayscale images, using a stretched color ramp. A neat little tool I wasn’t familiar with before is the Pixel Inspector. By moving your cursor over the raster, you get a look at the 8-bit color value of each pixel and thus a sense of the range values for your feature.
With a bit of trial and error, you can narrow down the range of pixel values that best outlines the features you’re interested in, and by using the classified color ramp on the Symbology tab, you’re able to check what areas will be included when using as certain range of values.
Now it’s time to create a new raster file that contains only those colors making up the features of interest. Of course, there will be some other noise of similarly colored features. But I am hoping that upon merging the three bands, only those areas that are part of all three rasters will be left over.
Turns out that to turn my original one-band raster into one containing only the pixels of interest, I need the Raster Calculator, which, in understand, is a feature of Spatial Analyst.
Time to look for Open Source help. And I quickly found OpenEv, which is part of FWTools, used GDAL, has Python bindings, and provides all kinds of raster manipulation capabilities. All I had to do was open my one-band raster and use some Python to run my own – VERY CRUDE – raster calculation. I don’t know much about numpy (Python’s module for all kinds of numerical/mathematical tricks) but this was pretty straight forward and goes something like this:
#Band1.img is the single band raster saved in ArcGIS
#columns and rows are the number of columns/rows respectively
# 100 and 180 are the min/max pixel values of interest
array1 = LoadFile(`Band1.img`)
for c in range(columns):
for r in range(rows):
pixel = array1[c:c+1,r:r+1]
if pixel < 100 or pixel > 180:
Now, I can export array1 as another GeoTIFF and open it in ArcGIS. Basically, I get a raster where the pixels of interest are unchanged, and everything else has been set to zero or BLACK. That’s as far as I’ve gotten. Now, I just need to the same for all three bands and work on recombing them.
PS: I stumbled across another open source project that might help with raster file – TerraLib/TerraView. But I haven’t had a chance to try it out.