Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparent parts of tiled imagery #1

Closed
kylebarron opened this issue Dec 17, 2019 · 1 comment
Closed

Transparent parts of tiled imagery #1

kylebarron opened this issue Dec 17, 2019 · 1 comment

Comments

@kylebarron
Copy link
Member

In some places, e.g. the San Gabriel mountains, there's an ugly green:
image

It's clear when you look with no background, that these are parts of the imagery that are transparent:
image

This is because I'm currently doing

gdalbuildvrt -srcnodata 0 data/naip.vrt data/raw/*.jp2

This makes all image pixels with 0,0,0[,0?] set as nodata, which makes them transparent when rendered. The issue is that there are some places in the original imagery that are so heavily shaded that they actually have pure-black values. For example, this is the original image with correct colors:
image

@kylebarron
Copy link
Member Author

Here's the way to fix this:

I want all areas with source data to have full opacity, and I want all areas with no original NAIP image to be fully transparent.

If you actually read through the gdalbuildvrt options, you'd see:

-b <band>:

Select an input to be processed. Bands are numbered from 1. If input bands not set all bands will be added to vrt. Multiple -b switches may be used to select a set of input bands.

-addalpha:

Adds an alpha mask band to the VRT when the source raster have none. Mainly useful for RGB sources (or grey-level sources). The alpha band is filled on-the-fly with the value 0 in areas without any source raster, and with value 255 in areas with source raster. The effect is that a RGBA viewer will render the areas without source rasters as transparent and areas with source rasters as opaque.

Since the source .jp2 files already have an alpha band, select only the first three bands, and then also pass -addalpha when constructing the VRT:

gdalbuildvrt -b 1 -b 2 -b 3 -addalpha naip.vrt *.jp2

Then when you tile it, it's still transparent in areas with no source:
image
but fully black areas of the source are correctly opaque:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant