[gdal-dev] What is the best strategy for handling multiple banded tiffs
Stephen Woodbridge
woodbri at swoodbridge.com
Wed Apr 12 14:40:56 PDT 2017
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.
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)
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?
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:
> >
> > # remove any collar
> > nearblack -co TILED=YES -of GTiff -nb 0 -near 0 -setmask -q -o temp1.tif
> > doqq.tif
> >
> > # warp to EPSG:4326 (does -dstalpha convert mask band to an alpha band?)
>
> Yes
>
> > gdalwarp -t_srs EPSG:4326 -dstalpha -co TILED=YES temp1.tif rgba.tif
> >
> > # make sobel gray scale single band image
> > makesobel.py rgba.tif sobel.tif
> >
> > # create a temp.vrt file with bands R, G, B, Alpha|mask, IR, sobel
> >
> > # and finally build a tif using the temp.vrt
> > # I'm not sure what is the best way build the final tif given the mask
> > # and whether I should use gdalwarp or gdal_translate for this step
> > gdal_translate -co TILED=YES -co JPEG_QUALITY=90 -co COMPRESS=JPEG
> > --CONFIG GDAL_TIFF_INTERNAL_MASK YES temp.vrt final.tif
>
> --> This will only work as intended if there's a mask band identified as
> a mask and not an alpha band in the VRT.
>
> >
> > # and build overviews
> > gdaladdo -clean -r average final.tif 2 4 8 16 32 64 128
> >
> > I'm not clear on how the mask band or alpha channel(band?) interacts
> > with the various commands at each step in the workflow.
> >
> > Thanks,
> > -Steve
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
More information about the gdal-dev
mailing list