[gdal-dev] What is the best strategy for handling multiple banded tiffs

Even Rouault even.rouault at spatialys.com
Wed Apr 12 15:26:28 PDT 2017


On mercredi 12 avril 2017 17:40:56 CEST Stephen Woodbridge wrote:
> I'm working with:
> 
> GDAL 1.10.1, released 2013/08/26 (native)
> GDAL 2.1.0, released 2016/04/25  (in a docker container)
> 
> All these results are from 2.1.
> 
> I don't think I need the nearblack call as the NAIP imagery does not
> appear to have collars. So I'm removing it from the workflow for now.
> 
> The source DOQQ has these bands where band 4 is the IR:
> Band 1 Block=6472x1 Type=Byte, ColorInterp=Red
> Band 2 Block=6472x1 Type=Byte, ColorInterp=Green
> Band 3 Block=6472x1 Type=Byte, ColorInterp=Blue
> Band 4 Block=6472x1 Type=Byte, ColorInterp=Undefined
> 
> gdalwarp -t_srs EPSG:4326 -dstalpha  -co TILED=YES
> m_3311805_ne_11_1_20140513.tif epsg4326.tif
> 
> Band 1 Block=256x256 Type=Byte, ColorInterp=Gray
> Band 2 Block=256x256 Type=Byte, ColorInterp=Undefined
> Band 3 Block=256x256 Type=Byte, ColorInterp=Undefined
> Band 4 Block=256x256 Type=Byte, ColorInterp=Undefined
> Band 5 Block=256x256 Type=Byte, ColorInterp=Alpha
> 
> So this is annoying, but probably fixable, band 4 is the IR if I add an
> *.aux.xml file setting the color interupt, at least on 2.1, adding it on
> 1.10.1 does not help. It does not appear that it is possible to create a
> mask band only an alpha band at this point.

You need to use gdal_translate -mask to "convert" an alpha band to a mask band.

> 
> The compressing this:
> 
> gdal_translate -co TILED=YES -co JPEG_QUALITY=90 -co COMPRESS=JPEG -b 1
> -b 2 -b 3 -b 4 -mask 5 epsg4326.tif out.tif
> 
> Band 1 Block=256x256 Type=Byte, ColorInterp=Gray
>    Mask Flags: PER_DATASET
> Band 2 Block=256x256 Type=Byte, ColorInterp=Green
>    Mask Flags: PER_DATASET
> Band 3 Block=256x256 Type=Byte, ColorInterp=Blue
>    Mask Flags: PER_DATASET
> Band 4 Block=256x256 Type=Byte, ColorInterp=Alpha
>    Mask Flags: PER_DATASET
> 
> It dropped the source band 4 (IR)

My hypothesis is that band 4 is the IR, but with a wrong color interpretation. Perhaps use a 
VRT as an intermediate to fix color interpretations. I've done various fixes in trunk those last 
months related to color interpretation when writing TIFF.

> 
> gdal_translate -co TILED=YES -co JPEG_QUALITY=90 -co COMPRESS=JPEG
> epsg4326.tif out2.tif
> 
> Input file size is 7232, 7056
> 0...10...20...30...40...50...60...70...80...90...100 - done.
> ERROR 1: JPEGLib:Too many color components: 5, max 4
> ERROR 1: WriteEncodedTile/Strip() failed.
> ERROR 1: JPEGLib:Too many color components: 5, max 4
> ERROR 1: WriteEncodedTile/Strip() failed.
> ERROR 1: JPEGLib:Too many color components: 5, max 4
> ERROR 1: WriteEncodedTile/Strip() failed.
> 
> So is it possible to compress multiple bands using jpeg compression?
> (other than an RGB or RGBA or RGB mask?

Yes, but you need to add -co INTERLEAVE=BAND

> 
> So, if I want to end up with a single tif file with bands (R, G, B,
> Alpha|mask, IR, sobel) that is jpeg compressed is this possible?
> 
> What is the workflow to do that?
> 
> Or is the best I can do is to create separate RGBA file, an IR file and
> a sobel file and bring them together via a VRT file?
> 
> Thanks,
>    -Steve
> 
> On 4/12/2017 2:01 PM, Even Rouault wrote:
> > On mercredi 12 avril 2017 13:23:06 CEST Stephen Woodbridge wrote:
> >  > Hi all,
> >  > 
> >  > 
> >  > 
> >  > I'm reworking my code dealing with NAIP imagery that has R, G, B, IR
> >  > bands, and I generate a mask band when reprojecting it. I also have the
> >  > option to generate another computed band based on a sobel operator.
> >  > 
> >  > In the past, I separated them R, G, B, mask into jpeg ycbcr compressed
> >  > tiff and had separate files for the IR, and the sobel data and used a
> >  > VRT file to pull all these together into a single image for additional
> >  > processing.
> >  > 
> >  > Ideally, I would like to have one file, rather than 4 files (RGB, IR,
> >  > sobel, and the VRT) because over large areas the management of all
> >  > these
> >  > files is a pain. Also when displaying and working with large areas I
> >  > need to mosaic the images into a seemless area using a vrt file or
> >  > tileindex.
> >  > 
> >  > I need a way to display the various bands, and mapserver is my tool of
> >  > choice, but I probably need to be able to display them via qgis also,
> >  > which I have not experience with but reading older posts, I might need
> >  > to create a vrt file. In mapserver I can select bands using PROCESSING
> >  > options on layers.
> >  > 
> >  > Questions?
> >  > 
> >  > 1. Does it make sense to try and do this with one tiff with 6 bands?
> >  > 2. What would be the best workflow for doing this? I'm thinking
> >  > something like:
> >  > 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20170413/74c047ed/attachment-0001.html>


More information about the gdal-dev mailing list