[gdal-dev] Giventiff with colortable, how do i assign one of the colors to be an alpha channel
Isaac Gerg
isaac.gerg at gergltd.com
Wed Jan 16 11:58:51 PST 2013
Even,
Thanks for your quick response.
I believe I understand that three options you presented me. I believe
option 1 is viable but like you mentioned will only work with GDAL
software. Options 2 and 3 are good but, especially with option 3, the
resulting tifs are too large.
I have 20 .tif which are 3MB a piece. Together, they form trackline of a
sensor data. I would like to load this information into a WMS server for
display in Google Earth or Arc Explorer. Currently I am using Geoserver.
Anyways, I must mosaic these 20 .tifs together. These tifs are indexed
images with a colormap. Here is my current algorithm:
1. Expand images to RGBA using gdal_translate
2. Rotate images north up using gdal_warp
3. Mosiac images using gdal_merge with -co COMPRESS=LZW -co PREDICTOR=1 -ot
Byte -co TILED=YES -n 0
At this point, I now have an RGBA image that is huge (300MB). With all the
tile collections I must process, 300MB is too big. I was thinking the
total would be around (20 tiles)*(3MB per tile) = 60MB. 300 is simply
unacceptable.
4. Run the gdal_retile to make image pyramid. This will yeild a size that
is roughly twice that of my mosiac.
Is there any way I can make the RGBA file in step 3 smaller in size
specifically to match the theoretical size of 60MB?
Thanks again,
Isaac
On Wed, Jan 16, 2013 at 2:21 PM, Even Rouault
<even.rouault at mines-paris.org>wrote:
> Le mercredi 16 janvier 2013 20:03:14, Isaac Gerg a écrit :
> > Hi All,
> >
> > I have a tiff in which each pixel is a single byte (0-255) which
> references
> > a colortable. Each element of the colortable has 4 values (RGBA).
> >
> > I would like to convert my "black" color (entry 1 in the color table
> > (0,0,0,255)) to be transparent (new colortable entry is (0,0,0,0))
> >
> > Another way to say it is, how do I create a tiff with an indexed colormap
> > but also have it contain an alpha channel?
>
> TIFF color palette are only RGB, not RGBA. What you can do, however, is
> assign
> a nodata value (note this is a GDAL specific TIFF tag that will only be
> understood by GDAL based software)
>
> gdal_translate src.tif src_with_nodata.tif -a_nodata 0
>
> You can create a TIFF with an indexed colormap and an alpha channel with
> the
> following extra steps :
>
> gdal_translate src_with_nodata.tif mask.tif -b mask
> gdalbuildvrt tmp.vrt src.tif mask.tif -separate
> gdal_translate src.tif src.vrt -of VRT
>
> the with a text editor copy the lines that look line the following ones
> from
> src.vrt
>
> <ColorInterp>Palette</ColorInterp>
> <ColorTable>
> <Entry c1="112" c2="120" c3="56" c4="255" />
> [...]
> <Entry c1="204" c2="208" c3="164" c4="255" />
> </ColorTable>
>
> and paste them just below <VRTRasterBand dataType="Byte" band="1"> in
> tmp.vrt
>
> Finally :
>
> gdal_translate tmp.vrt pct_with_alpha.tif -co ALPHA=YES
>
> That's it. But I'm not sure that this will be properly displayed by
> viewers.
>
> A safest alternative would be to build a RGBA TIFF :
>
> gdal_translate -expand rgb src.tif rgb.tif
> gdal_translate -b 1 rgb.tif r.tif
> gdal_translate -b 2 rgb.tif g.tif
> gdal_translate -b 3 rgb.tif b.tif
> gdalbuildvrt rgba.vrt r.tif g.tif b.tif mask.tif -separate
> gdal_translate rgba.vrt rgba.tif -co ALPHA=YES
>
> >
> > Thanks in advance,
> > Isaac
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20130116/606db752/attachment.html>
More information about the gdal-dev
mailing list