Re: [gdal-dev] JPEG compressed COGs nodata

2022-07-25 Thread Matt.Wilkie
For those not wanting or needing to take the processing hit of running 
nearblack, use gdalwarp and -dstalpha to create the alpha channel, and use 
intermediate VRT to save space and more time. Something like this:

gdalwarp -srcnodata 0 -dstalpha -of vrt source.tif xx-interim.vrt

gdal_translate -of COG {...} xx-interim.vrt final.tif


-Matt

From: gdal-dev  On Behalf Of Travis Kirstine
Sent: July 22, 2022 9:04 AM
To: gdal dev 
Subject: Re: [gdal-dev] JPEG compressed COGs nodata


You don't often get email from 
traviskirst...@gmail.com<mailto:traviskirst...@gmail.com>. Learn why this is 
important<https://aka.ms/LearnAboutSenderIdentification>

To answer my own question I believe the answer is that you need to create an 
alpha band when working with RGB datasets to have JPEG compressed COGs without 
compression artifacts in the nodata areas.  Creating a internal mask on the 
source data may work as well but I haven't tried.

# add a alpha band using the nearblack utility
nearblack -setalpha rgb_nodata.tif -o rgba.tif
# create the COG
gdal_translate -of COG  -co COMPRESS=JPEG -co 
TILING_SCHEME=GoogleMapsCompatible -co NUM_THREADS=ALL_CPUS -co BIGTIFF=YES 
rgba.tif cog.tif

Regards




On Tue, 19 Jul 2022 at 15:19, Travis Kirstine 
mailto:traviskirst...@gmail.com>> wrote:
I've been trying to create a COG with JPEG compression with transparent nodata 
values without much success.  Is this possible without creating a secondary 
mask?

Any hints?

Regards
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] JPEG compressed COGs nodata

2022-07-22 Thread Travis Kirstine
To answer my own question I believe the answer is that you need to create
an alpha band when working with RGB datasets to have JPEG compressed COGs
without compression artifacts in the nodata areas.  Creating a internal
mask on the source data may work as well but I haven't tried.

# add a alpha band using the nearblack utility
nearblack -setalpha rgb_nodata.tif -o rgba.tif
# create the COG
gdal_translate -of COG  -co COMPRESS=JPEG -co
TILING_SCHEME=GoogleMapsCompatible -co NUM_THREADS=ALL_CPUS -co BIGTIFF=YES
rgba.tif cog.tif

Regards




On Tue, 19 Jul 2022 at 15:19, Travis Kirstine 
wrote:

> I've been trying to create a COG with JPEG compression with transparent
> nodata values without much success.  Is this possible without creating a
> secondary mask?
>
> Any hints?
>
> Regards
>
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] JPEG compressed COGs nodata

2022-07-19 Thread Frank Warmerdam
Travis,

I am not aware of a good way to do this.   What I do is create separate
mask directories looking like te following.  Note the "Subfile Type:
transparency mask (4 = 0x4)" directories.  It isn't clear that all
applications will honor these, but modern GDAL treats this as a PER_DATASET
mask, and modern GDAL using applications that honor this style of masking
will support the mask properly.   I think modern QGIS does for instance,
and MapServer.   I could do some digging for the GDAL script code that
makes these if you like.

Best regards,
Frank


$ tiffinfo 20200708_082104_1002_Browse.tif
TIFFReadDirectory: Warning, Unknown field with tag 33550 (0x830e)
encountered.
TIFFReadDirectory: Warning, Unknown field with tag 33922 (0x8482)
encountered.
TIFFReadDirectory: Warning, Unknown field with tag 34735 (0x87af)
encountered.
TIFFReadDirectory: Warning, Unknown field with tag 34737 (0x87b1)
encountered.
TIFFReadDirectory: Warning, Unknown field with tag 42112 (0xa480)
encountered.
TIFF Directory at offset 0x17794e (1538382)
  Image Width: 5870 Image Length: 2889
  Tile Width: 256 Tile Length: 256
  Bits/Sample: 8
  Sample Format: unsigned integer
  Compression Scheme: JPEG
  Photometric Interpretation: YCbCr
  YCbCr Subsampling: 2, 2
  Samples/Pixel: 3
  Planar Configuration: single image plane
  Reference Black/White:
 0: 0   255
 1:   128   255
 2:   128   255
  ImageDescription: {"fp_center": [23.21221629852675, -19.107257323766635]}
  DateTime: 2020:07:08 08:21:04
  Tag 33550: 4.777314,4.777314,0.00
  Tag 33922:
0.00,0.00,0.00,2569932.323447,-2160669.364808,0.00
  Tag 34735:
1,1,0,7,1024,0,1,1,1025,0,1,1,1026,34737,25,0,2049,34737,7,25,2054,0,1,9102,3072,0,1,3857,3076,0,1,9001
  Tag 34737: WGS 84 / Pseudo-Mercator|WGS 84|
  Tag 42112: 
  red
  green
  blue


  JPEG Tables: (142 bytes)
TIFF Directory at offset 0xb6a (2922)
  Subfile Type: transparency mask (4 = 0x4)
  Image Width: 5870 Image Length: 2889
  Tile Width: 256 Tile Length: 256
  Bits/Sample: 1
  Sample Format: unsigned integer
  Compression Scheme: AdobeDeflate
  Photometric Interpretation: transparency mask
  Samples/Pixel: 1
  Planar Configuration: single image plane
  Predictor: none 1 (0x1)
TIFF Directory at offset 0x14b8 (5304)
  Subfile Type: reduced-resolution image (1 = 0x1)
  Image Width: 1468 Image Length: 723
  Tile Width: 128 Tile Length: 128
  Bits/Sample: 8
  Sample Format: unsigned integer
  Compression Scheme: JPEG
  Photometric Interpretation: YCbCr
  YCbCr Subsampling: 2, 2
  Samples/Pixel: 3
  Planar Configuration: single image plane
  Reference Black/White:
 0: 0   255
 1:   128   255
 2:   128   255
  JPEG Tables: (142 bytes)
TIFF Directory at offset 0x1888 (6280)
  Subfile Type: reduced-resolution image (1 = 0x1)
  Image Width: 734 Image Length: 362
  Tile Width: 128 Tile Length: 128
  Bits/Sample: 8
  Sample Format: unsigned integer
  Compression Scheme: JPEG
  Photometric Interpretation: YCbCr
  YCbCr Subsampling: 2, 2
  Samples/Pixel: 3
  Planar Configuration: single image plane
  Reference Black/White:
 0: 0   255
 1:   128   255
 2:   128   255
  JPEG Tables: (142 bytes)
TIFF Directory at offset 0x1aa8 (6824)
  Subfile Type: reduced-resolution image (1 = 0x1)
  Image Width: 367 Image Length: 181
  Tile Width: 128 Tile Length: 128
  Bits/Sample: 8
  Sample Format: unsigned integer
  Compression Scheme: JPEG
  Photometric Interpretation: YCbCr
  YCbCr Subsampling: 2, 2
  Samples/Pixel: 3
  Planar Configuration: single image plane
  Reference Black/White:
 0: 0   255
 1:   128   255
 2:   128   255
  JPEG Tables: (142 bytes)
TIFF Directory at offset 0x1c68 (7272)
  Subfile Type: reduced-resolution image/transparency mask (5 = 0x5)
  Image Width: 1468 Image Length: 723
  Tile Width: 128 Tile Length: 128
  Bits/Sample: 1
  Sample Format: unsigned integer
  Compression Scheme: AdobeDeflate
  Photometric Interpretation: transparency mask
  Samples/Pixel: 1
  Planar Configuration: single image plane
  Predictor: none 1 (0x1)
TIFF Directory at offset 0x1f56 (8022)
  Subfile Type: reduced-resolution image/transparency mask (5 = 0x5)
  Image Width: 734 Image Length: 362
  Tile Width: 128 Tile Length: 128
  Bits/Sample: 1
  Sample Format: unsigned integer
  Compression Scheme: AdobeDeflate
  Photometric Interpretation: transparency mask
  Samples/Pixel: 1
  Planar Configuration: single image plane
  Predictor: none 1 (0x1)
TIFF Directory at offset 0x2094 (8340)
  Subfile Type: reduced-resolution image/transparency mask (5 = 0x5)
  Image Width: 367 Image Length: 181
  Tile Width: 128 Tile Length: 128
  Bits/Sample: 1
  Sample Format: unsigned integer
  Compression Scheme: AdobeDeflate
  Photometric Interpretation: transparency mask
  Samples/Pixel: 1
  Planar Configuration: single image plane
  Predictor: none 1 (0x1)

On Tue, Jul 19, 2022 at 3:19 PM Travis Kirstine 
wrote:

> I've been trying to create a COG with JPEG compression with 

[gdal-dev] JPEG compressed COGs nodata

2022-07-19 Thread Travis Kirstine
I've been trying to create a COG with JPEG compression with transparent
nodata values without much success.  Is this possible without creating a
secondary mask?

Any hints?

Regards
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev