[Gdal-dev] Gdalwarp color corruption

Matt Wilkie matt.wilkie at gov.yk.ca
Tue Jan 16 19:58:09 EST 2007


Hi Craig,

After last talking to you on friday I pushed my discomfort with gdalwarp 
out of the way and tackled learning it earnestly. I'm very happy to 
report I've found a workflow which works well for us, unlike the 
tortuous spaghetti route I told you about. :) So now I have output 
images which are both colour-faithul and edge-sharp, unlike the ones I 
put up for you to see last week.

The method is simple, but not very efficient:
- Convert 256 colour image to RGB,
- restore georeferencing,
- project and resample,
- convert back to 256c,
- restore georeferencing.

Command sequence:

   :: convert to rgb
   pal2rgb -c lzw orig.tif orig-rgb.tif

   :: restore lost georeferencing
   listgeo -proj4 orig.tif orig.prj
   geotifcp -g orig.prj orig-rgb.tif orig-rgb-geo.tif

   :: project to albers
   gdalwarp --optfile=utm2alb.opt orig-rgb-geo.tif out-rgb.tif

#optfile
-co compress=lzw
-rc
-wm 1500
-t_srs "+proj=aea +lat_1=61.666666667 +lat_2=68.000000000 
+lat_0=59.000000000 +lon_0=-132.500000000 +x_0=500000.000 
+y_0=500000.000 +ellps=GRS80 +units=m"

   :: convert back to 256 colours
   rgb2pct -n 256 out-rgb.tif xx-out-256c.tif

   :: compress 256c
   gdal_translate -co compress=lzw xx-out-256c.tif out-256c.tif

   :: delete intermediate files
   del orig-rgb.tif orig-rgb-geo.tif orig.prj xx-orig-256c.tif


The final 256c images do have dithering artifacts at high zoom levels 
and bright white is now a dim white (RGB:248,248,248).


If I use nconvert instead of pct2rgb to get back to 256c the colour 
fidelity is perfect, although the index order changes. My nconvert 
command is below. I don't know if all the options are needed, probably not:

   :: use nconvert to get back to 256c instead of rgb2pct
   nconvert -npcd 2 -ctype grey -corder inter -ratio -rtype lanczos \
    -c 3 -colours 256 -out tiff -o xx-out-256c.tif out-rgb.tif

   :: restore lost georefencing
   listgeo -proj4 out-rgb.tif  > out-rgb.prj
   geotifcp -g out-rgb.prj out-256c.tif out-256c-geo.tif


I've asked nconvert author Pierre Gougelet about making it geotiff aware 
and he's going to look into it. To keep the whole toolchain open source 
though would require adding lanczos or some other colour reduction 
algorithm to rgb2pct (I think).





Craig Miller wrote:
> I've been using gdalwarp to reproject USGS quads (single band geotif images
> with color table) from UTM zone 10/11 to geographic (EPSG:4326).  If I use
> nearest neighbor sampling (-rn) the color table gets translated correctly,
> but if I use bilinear, cubic, or cubic spline resampling the color table is
> corrupted.  For example, blue water turns brown.  As nearest neighbor
> sampling doesn't always offer up the smoothest results I'm hoping to get
> cubic spline resampling working.  Any suggestions on how to get this working
> w/o corrupting my color table?
> 
> I'm using gdal out of CVS from a couple of weeks ago.
> 
> Gdalwarp -rcs -co "COMPRESS=LZW" -co "TILED=YES" -wo "INIT_DEST=NO_DATA"
> -t_srs EPSG:4326 infile.tif ..\geo\outfile.tif
> 
> I'd be happy to provide sample images, but they are a bit large so I didn't
> want to send them to the list.
> 
> Thanks for the help,
> Craig
> 
> 
> 
> _______________________________________________
> Gdal-dev mailing list
> Gdal-dev at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/gdal-dev
> 
> 


-- 
matt wilkie
--------------------------------------------
Geographic Information,
Information Management and Technology,
Yukon Department of Environment
10 Burns Road * Whitehorse, Yukon * Y1A 4Y9
867-667-8133 Tel * 867-393-7003 Fax
http://environmentyukon.gov.yk.ca/geomatics/
--------------------------------------------




More information about the Gdal-dev mailing list