[gdal-dev] gtiff with internal mask

Duarte Carreira DCarreira at edia.pt
Fri Jul 19 04:26:38 PDT 2013


Ok, para conseguir construir as pirâmides temos de ter a máscara separada e não incluída no próprio tiff.

Para isso basta alterar o 3º passo que cria efectivamente o tiff a partir do vrt, removendo a opção de criar a máscara interna, ficando assim:
gdal_translate -co alpha=no -co photometric=ycbcr -co interleave=pixel -co tiled=yes -co compress=jpeg testmask_uncomp.vrt test_finalmask.tif

Isto basta para que seja criado um tif rgb e um ficheiro .msk separados.

*** Para criar um rgb+iv num só tiff, com máscara! ***

Alterar o mosaico vrt criado no 2º passo, que já inclui a máscara, e criar uma banda Gray com origem no mosaico vrt dos infravermelhos.
Depois é só converter mas usando as opções: -co alpha=no -co photometric=rgb e talvez -co interleave=band (para não dar erro). Não podemos usar ycbcr porque só dá para 3 bandas e nós temos 4.

DC



-----Mensagem original-----
De: Duarte Carreira 
Enviada: quinta-feira, 18 de Julho de 2013 13:01
Para: 'Even Rouault'
Cc: 'gdal-dev at lists.osgeo.org'
Assunto: RE: [gdal-dev] gtiff with internal mask

So... now I 've got issues building the overviews. Gdaladdo loses the transparency so I get to see black areas where I was supposed to see nothing. When I zoom in black disappears.

Any known way to overcome this?

Thanks,
Duarte



-----Mensagem original-----
De: Duarte Carreira
Enviada: quarta-feira, 17 de Julho de 2013 19:41
Para: 'Even Rouault'
Cc: gdal-dev at lists.osgeo.org
Assunto: RE: [gdal-dev] gtiff with internal mask

Well, you're right... I messed up recreating the footsteps...

So, cleaning up:

1) create a rgba vrt using gdalwarp to cut the original mosaic with a shapefile gdalwarp -multi -wm 480 --config GDAL_CACHEMAX 312 -co alpha=yes -dstalpha -cutline shapes\index_diss.shp -of vrt originalmosaic.vrt test_rgba_uncomp.vrt

2) create a masked uncompressed vrt using gdal_translate (because I couldn't compress right away, with errors of missing StripOffsets field) gdal_translate -b 1 -b 2 -b 3 -mask 4 -co alpha=no -co photometric=rgb -co interleave=pixel -co tiled=yes --config GDAL_TIFF_INTERNAL_MASK YES -of vrt  test_rgba_uncomp.vrt testmask_uncomp.vrt

3) create final masked compressed tiff using gdal_translate gdal_translate -co alpha=no -co photometric=ycbcr -co interleave=pixel -co tiled=yes -co compress=jpeg --config GDAL_TIFF_INTERNAL_MASK YES testmask_uncomp.vrt test_finalmask.tif

The power of VRT amazes me!

Also regarding sizes: I still got the same ratio of 8x smaller.

To use this in QGIS you still have to create a rgba vrt:
4) gdal_translate -of VRT -b 1 -b 2 -b 3 -b mask test_finalmask.tif test_finalmask_qgis.vrt (couldn't get the 4ª band to be recognized as an alpha band though)

So I think now it's correct... I am going to apply this to a real-case mosaic and report back...

Duarte

-----Mensagem original-----
De: Even Rouault [mailto:even.rouault at mines-paris.org]
Enviada: quarta-feira, 17 de Julho de 2013 13:45
Para: Duarte Carreira
Cc: gdal-dev at lists.osgeo.org
Assunto: Re: [gdal-dev] gtiff with internal mask

Le mercredi 17 juillet 2013 14:23:29, Duarte Carreira a écrit :
> Hi Even.
> 
> Thanks so much for your tip! It works. I did have to specify I did not 
> want an alpha band when cutting with the shapefile:
> 
> gdalwarp -multi -wm 480 --config GDAL_CACHEMAX 256 -co 
> photometric=ycbcr -co compress=jpeg -co alpha=no --config 
> GDAL_TIFF_INTERNAL_MASK YES -cutline shapes\index_diss.shp vrtini.vrt 
> testmask.tif

Hum, what I don't understand is how the above will produce a mask band in the output file...

Does gdalinfo on testmask.tif show something like :

Band 1 Block=.... Type=Byte, ColorInterp=Red
  Mask Flags: PER_DATASET
Band 2 Block=.... Type=Byte, ColorInterp=Green
  Mask Flags: PER_DATASET
Band 3 Block=... Type=Byte, ColorInterp=Blue
  Mask Flags: PER_DATASET 

I think you would need to do the above in 2 steps:
1) gdalwarp to an uncompressed RGBA TIFF
2) gdal_translate to turn the RGBA into a YCbCr JPEG-compressed GTiff + mask band

> 
> Seems arcgis recognizes the masked tiff, but is much much slower 
> displaying than using a "normal" alpha band.

Perhaps adding -co TILED=YES will help ? (random guess)

> QGIS does need the vrt trick but then is as fast as usual.
> 
> Also, the size is must smaller when using an internal mask: from a 
> 219MB rgba,band interleaved,jpegd image to a 27MB ycbcr,pixel 
> interleaved,jpegd masked tiff (8x smaller). Unless I missed something...

Not completely surprising although more important than I would have expected. 
YCbCr compression usually gives a 2x to 3x compression bonus, and due to the usual nature of mask bands, the 1bit deflate compression of the mask band will give better results (both visually and in size) that the 8bit JPEG compression of the alpha band.

> 
> Thanks again!
> Duarte
> 
> -----Mensagem original-----
> De: Even Rouault [mailto:even.rouault at mines-paris.org]
> Enviada: terça-feira, 16 de Julho de 2013 18:58
> Para: gdal-dev at lists.osgeo.org
> Cc: Duarte Carreira
> Assunto: Re: [gdal-dev] gtiff with internal mask
> 
> Le mardi 16 juillet 2013 12:29:37, Duarte Carreira a écrit :
> > I'm trying to create gtiffs with transparent areas where there are 
> > voids between my original images.
> > 
> > I have successfully done it by using an alpha band but this process 
> > created 3x larger images. I think partly because of an additional 
> > 4th band and partly because I cannot use ycbcr to compress with 
> > jpeg. So I thought of using internal masks expecting to get smaller 
> > images but cannot get it to work.
> > 
> > When converting from the rgba image using -mask 4 I cannot "see" the 
> > transparency and get black areas:
> > 
> > gdal_translate -b 1 -b 2 -b 3 -ma sk 4 --config 
> > GDAL_TIFF_INTERNAL_MASK YES test_alpha.tif test_internalmask.tif
> > 
> > I tried looking at the images using qgis and paint.net.
> 
> I know QGIS doesn't use the GDALGetMaskBand() API, so no real surprise 
> (that would likely be a possible QGIS enhancement). And paint.net 
> probably doesn't support this feature of the TIFF format either.
> 
> MapServer does support mask bands however.
> 
> For QGIS, you could workaround that however. Imagine that you have a 
> YCbCr TIFF + internal mask in.tif.
> 
> You can do : "gdal_translate -of VRT -b 1 -b 2 -b 3 -b mask in.tif out.vrt"
> 
> And QGIS should handle out.vrt as a regular RGBA dataset.
> 
> > Any hints or help appreciated.
> > 
> > Thanks,
> > Duarte
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > Duarte Carreira
> > Diretor | Dep. Informa??o Geogr?fica e Cartografia
> > 
> > www.edia.pt<http://www.edia.pt>
> > www.alqueva.com.pt<http://www.alqueva.com.pt>
> > Tel. +351 284315100
> > 
> > [http://www.edia.pt/edia/images/edia_logo2.gif]<http://www.edia.pt>
> 
> --
> Geospatial professional services
> http://even.rouault.free.fr/services.html

--
Geospatial professional services
http://even.rouault.free.fr/services.html



More information about the gdal-dev mailing list