Sorry about that. It has to do with the little progress indicator that runs when gdal processes a file. There are different ways of invoking it, and my mileage varies with each of them. I think it is based on what version of gdal you're using. Anyhow, 2 ways you can deal with this. I think with your version of gdal you can just remove the import statement, line 14 (
gdal.TermProgress = gdal.TermProgress_nocb ), entirely. If that doesn't work, just remove all 3 lines that have "TermProgress" in them. You won't have a status indicator then to tell you how far along the coloring is, but the program should run. Also, just fyi that the colorization won't be incredibly fast. It takes around 5 minutes to color an image that is 2500 x 2500 pixels on my machine. There is obviously room for optimization here ;).<br>
--<br><br><div class="gmail_quote">On Sat, Apr 11, 2009 at 5:05 PM, alvarez00 <span dir="ltr"><<a href="mailto:oalvarez00@gmail.com">oalvarez00@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hi Roger,<br>
<br>
I'm trying to run the python code you suggested but I keep getting this error :<br>
Traceback (most recent call last):<br>
File "discreet_gray2color.py", line 14, in <module><br>
gdal.TermProgress = gdal.TermProgress_nocb<br>
AttributeError: 'module' object has no attribute 'TermProgress_nocb' "<br>
<br>
I don't know if it's the version of gdal I'm using or something else. (i'm using gdal 1.4.1.0)<br>
<br>
thanks,<br>
<div><div></div><div class="h5"><br>
<br>
<br>
<br>
Here's another way you can do it, a Python script that will create discreet<br>
color classes from a grayscale image. It uses a function named MakeColor<br>
which is currently set to work on Z values between 0 and 255. You can test<br>
it by converting your file into an 8-bit version (gdal_translate -scale -ot<br>
Byte <infile> <outfile> ), and then running the tool on it. Once you see<br>
how it works, it should be pretty simple to modify the function to deal with<br>
the actual ranges in your data.<br>
<br>
Roger<br>
--<br>
<br>
On Thu, Apr 9, 2009 at 4:24 PM, alvarez00 <<a href="mailto:oalvarez00@gmail.com">oalvarez00@gmail.com</a>> wrote:<br>
<br>
><br>
> I'm trying to make a color ramp for a 1-band tiff file or a jpeg. I have a<br>
> 1-band tiff file and I converted that tiff file into VRT. I was reading some<br>
> of the posts and some suggest to modify the VRT file and add a ColorTable<br>
> tag but that doesn't work. My objective is to show the tiff(or)jpeg on<br>
> google earth. I'm running version 1.4.1.0 of gdal. Below is the VRT file<br>
> without any modifications. What I modify was the<br>
> '<ColorInterp>Gray</ColorInterp>' to '<ColorInterp>Palette</ColorInterp>'<br>
> and added a ColorTable.<br>
><br>
> VRTDataset rasterXSize="1200" rasterYSize="1096"><br>
> <SRS>GEOGCS[&quot;NAD83&quot;,DATUM[&quot;North_American_Datum_1983&quot;,SPHEROID[&quot;GRS<br>
> 1980&quot;,6378137,298.2572221010002,AUTHORITY[&quot;EPSG&quot;,&quot;7019&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;6269&quot;]],PRIMEM[&quot;Greenwich&quot;,0],UNIT[&quot;degree&quot;,0.0174532925199433],AUTHORITY[&quot;EPSG&quot;,&quot;4269&quot;]]</SRS><br>
> <GeoTransform> -1.2459079918952935e+02, 8.9964705882352915e-03,<br>
> 0.0000000000000000e+00, 4.2216820949146452e+01, 0.0000000000000000e+00,<br>
> -8.9964705882352915e-03</GeoTransform><br>
> <Metadata><br>
> <MDI key="AREA_OR_POINT">Area</MDI><br>
> </Metadata><br>
> <VRTRasterBand dataType="Float32" band="1"><br>
> <Metadata/><br>
> <NoDataValue>-3.40282346638529E+38</NoDataValue><br>
> <ColorInterp>Gray</ColorInterp><br>
> <SimpleSource><br>
> <SourceFilename<br>
> relativeToVRT="1">GoesWest1V1561915.tif</SourceFilename><br>
> <SourceBand>1</SourceBand><br>
> <SrcRect xOff="0" yOff="0" xSize="1200" ySize="1096"/><br>
> <DstRect xOff="0" yOff="0" xSize="1200" ySize="1096"/><br>
> </SimpleSource><br>
> </VRTRasterBand><br>
> </VRTDataset><br>
><br>
> --<br>
> View this message in context:<br>
> <a href="http://n2.nabble.com/1-band-TIFF-FILE-color-ramp-NEEDED-tp2613963p2613963.html" target="_blank">http://n2.nabble.com/1-band-TIFF-FILE-color-ramp-NEEDED-tp2613963p2613963.html</a><br>
> Sent from the GDAL - Dev mailing list archive at Nabble.com.<br>
><br>
> _______________________________________________<br>
> gdal-dev mailing list<br>
> <a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
> <a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
><br>
<br>
</div></div>#! /usr/bin/env python<br>
<br>
# Create a colored image based on LUT in MakeColor function<br>
<br>
# Author: Roger Andre, October 2008<br>
<br>
# Usage: discreet_gray2color.py <infile> <outfile><br>
<br>
from osgeo import gdal<br>
import sys<br>
import numpy<br>
import os.path<br>
gdal.TermProgress = gdal.TermProgress_nocb<br>
<br>
src_file = sys.argv[1]<br>
dst_file = sys.argv[2]<br>
out_bands = 3<br>
<br>
def MakeColor(z_value):<br>
'''LUT for color ramp. Keys are pixel values, hash values are RGB triplets.'''<br>
color_dict = {<br>
0:[102,0,255],<br>
25:[20,82,255],<br>
50:[0,194,224],<br>
75:[0,255,122],<br>
100:[41,255,0],<br>
125:[204,255,0],<br>
150:[245,194,0],<br>
175:[224,118,0],<br>
200:[168,46,0],<br>
225:[105,0,0],<br>
250:[64,0,0],<br>
255:[0,0,0]}<br>
<br>
key_list = color_dict.keys()<br>
key_list.sort()<br>
while len(key_list) > 0:<br>
last_val = key_list[-1]<br>
if z_value >= last_val:<br>
return color_dict[last_val]<br>
else:<br>
key_list.remove(last_val)<br>
<br>
# Print some info<br>
print "Creating %s" % (dst_file)<br>
<br>
# Open source file<br>
src_ds = gdal.Open( src_file )<br>
src_band = src_ds.GetRasterBand(1)<br>
<br>
# create destination file<br>
dst_driver = gdal.GetDriverByName('GTiff')<br>
dst_ds = dst_driver.Create(dst_file, src_ds.RasterXSize, src_ds.RasterYSize, out_bands, gdal.GDT_Byte)<br>
<br>
# create output bands<br>
band1 = numpy.zeros([src_ds.RasterYSize, src_ds.RasterXSize])<br>
band2 = numpy.zeros([src_ds.RasterYSize, src_ds.RasterXSize])<br>
band3 = numpy.zeros([src_ds.RasterYSize, src_ds.RasterXSize])<br>
<br>
# set the projection and georeferencing info<br>
dst_ds.SetProjection( src_ds.GetProjection() )<br>
dst_ds.SetGeoTransform( src_ds.GetGeoTransform() )<br>
<br>
# read the source file<br>
gdal.TermProgress( 0.0 )<br>
for iY in range(src_ds.RasterYSize):<br>
src_data = src_band.ReadAsArray(0,iY,src_ds.RasterXSize,1)<br>
col_values = src_data[0] # array of z_values, one per row in source data<br>
for iX in range(src_ds.RasterXSize):<br>
z_value = col_values[iX]<br>
# print z_value # uncomment to see what value breaks color ramp<br>
[R,G,B] = MakeColor(z_value)<br>
band1[iY][iX] = R<br>
band2[iY][iX] = G<br>
band3[iY][iX] = B<br>
gdal.TermProgress( (iY+1.0) / src_ds.RasterYSize )<br>
<br>
# write each band out<br>
dst_ds.GetRasterBand(1).WriteArray(band1)<br>
dst_ds.GetRasterBand(2).WriteArray(band2)<br>
dst_ds.GetRasterBand(3).WriteArray(band3)<br>
<br>
dst_ds = None<br>
<div class="im"><br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
<br>
<br>
</div><font color="#888888">--<br>
View this message in context: <a href="http://n2.nabble.com/1-band-TIFF-FILE-color-ramp-NEEDED-tp2613963p2622398.html" target="_blank">http://n2.nabble.com/1-band-TIFF-FILE-color-ramp-NEEDED-tp2613963p2622398.html</a><br>
</font><div><div></div><div class="h5">Sent from the GDAL - Dev mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</div></div></blockquote></div><br>