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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Stephen Woodbridge
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?)
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

# 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

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What is the best strategy for handling multiple banded tiffs

Even Rouault-2

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

>

> _______________________________________________

> gdal-dev mailing list

> [hidden email]

> https://lists.osgeo.org/mailman/listinfo/gdal-dev

 

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What is the best strategy for handling multiple banded tiffs

Stephen Woodbridge
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

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What is the best strategy for handling multiple banded tiffs

Even Rouault-2

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:

> > >

> > > # 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

>

> _______________________________________________

> gdal-dev mailing list

> [hidden email]

> https://lists.osgeo.org/mailman/listinfo/gdal-dev

 

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What is the best strategy for handling multiple banded tiffs

Stephen Woodbridge
In reply to this post by Stephen Woodbridge
Hi Even,

Thanks that helped a lot.

Here are the results I'm getting now in case they help you with color
interp fixes. I'm not sure about the *.aux.xml files that get created
but they do not seem to always represent all the bands that gdalinfo
reports. In particular the alpha band does not show up in them, but that
may be by design similar to the fact that Undefined bands also do not
show up.

Anyway running through all these variations in options I helping me to
get a better handle on how things work.

Your help is much appreciated and has gotten me over the immediate
hurdles that were blocking me.

Thank you again,
   -Steve


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

I created epsg4326.tif.aux.xml like:

<PAMDataset>
   <PAMRasterBand band="1">
     <ColorInterp>Red</ColorInterp>
   </PAMRasterBand>
   <PAMRasterBand band="2">
     <ColorInterp>Green</ColorInterp>
   </PAMRasterBand>
   <PAMRasterBand band="3">
     <ColorInterp>Blue</ColorInterp>
   </PAMRasterBand>
   <PAMRasterBand band="4">
     <ColorInterp>Gray</ColorInterp>
   </PAMRasterBand>
   <PAMRasterBand band="5">
     <ColorInterp>Alpha</ColorInterp>
   </PAMRasterBand>
</PAMDataset>

and now get bands defined like as expected (the gray band is the IR):

Band 1 Block=256x256 Type=Byte, ColorInterp=Red
Band 2 Block=256x256 Type=Byte, ColorInterp=Green
Band 3 Block=256x256 Type=Byte, ColorInterp=Blue
Band 4 Block=256x256 Type=Byte, ColorInterp=Gray
Band 5 Block=256x256 Type=Byte, ColorInterp=Alpha

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

Files: out.tif
        out.tif.msk
        out.tif.aux.xml

Band 1 Block=256x256 Type=Byte, ColorInterp=Red
   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=Gray
   Mask Flags: PER_DATASET

gdal_translate -co TILED=YES -co JPEG_QUALITY=90 -co COMPRESS=JPEG -co
INTERLEAVE=BAND epsg4326.tif out2.tif

Files: out2.tif
        out2.tif.aux.xml

Band 1 Block=256x256 Type=Byte, ColorInterp=Red
Band 2 Block=256x256 Type=Byte, ColorInterp=Green
Band 3 Block=256x256 Type=Byte, ColorInterp=Blue
Band 4 Block=256x256 Type=Byte, ColorInterp=Gray
Band 5 Block=256x256 Type=Byte, ColorInterp=Alpha

with .aux.xml like:

<PAMDataset>
   <PAMRasterBand band="1">
     <ColorInterp>Red</ColorInterp>
   </PAMRasterBand>
   <PAMRasterBand band="2">
     <ColorInterp>Green</ColorInterp>
   </PAMRasterBand>
   <PAMRasterBand band="3">
     <ColorInterp>Blue</ColorInterp>
   </PAMRasterBand>
   <PAMRasterBand band="4">
     <ColorInterp>Gray</ColorInterp>
   </PAMRasterBand>
</PAMDataset>

gdal_translate -co TILED=YES -co JPEG_QUALITY=90 -co COMPRESS=JPEG -co
INTERLEAVE=BAND --config GDAL_TIFF_INTERNAL_MASK YES epsg4326.tif out3.tif

Files: out3.tif
        out3.tif.aux.xml

Band 1 Block=256x256 Type=Byte, ColorInterp=Red
Band 2 Block=256x256 Type=Byte, ColorInterp=Green
Band 3 Block=256x256 Type=Byte, ColorInterp=Blue
Band 4 Block=256x256 Type=Byte, ColorInterp=Gray
Band 5 Block=256x256 Type=Byte, ColorInterp=Alpha

And the .aux.xml is the same as above.

gdal_translate -co TILED=YES -co JPEG_QUALITY=90 -co COMPRESS=JPEG -co
INTERLEAVE=BAND -mask 5 --config GDAL_TIFF_INTERNAL_MASK YES
epsg4326.tif out4.tif

Files: out4.tif
        out4.tif.aux.xml

Band 1 Block=256x256 Type=Byte, ColorInterp=Red
   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=Gray
   Mask Flags: PER_DATASET
Band 5 Block=256x256 Type=Byte, ColorInterp=Alpha
   Mask Flags: PER_DATASET

And the .aux.xml is the same as above.



On 4/12/2017 5:40 PM, 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.
>
> 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
>
> _______________________________________________
> gdal-dev mailing list
> [hidden email]
> https://lists.osgeo.org/mailman/listinfo/gdal-dev


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Loading...