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

Apply same resampling method for mask and tile #105

Closed
vincentsarago opened this issue May 10, 2019 · 10 comments
Closed

Apply same resampling method for mask and tile #105

vincentsarago opened this issue May 10, 2019 · 10 comments
Assignees

Comments

@vincentsarago
Copy link
Member

in

with WarpedVRT(src_dst, **vrt_params) as vrt:
data = vrt.read(
out_shape=out_shape,
indexes=indexes,
window=out_window,
resampling=Resampling[resampling_method],
)
mask = vrt.dataset_mask(out_shape=(tilesize, tilesize), window=out_window)

we could end up (actual behavior) with using different resampling for mask and data which will result in bad masking.

@vincentsarago
Copy link
Member Author

@dionhaefner
Am I missing something here ? it seems to be the same in terracotta https://github.com/DHI-GRAS/terracotta/blob/master/terracotta/drivers/raster_base.py#L524-L529

@vincentsarago
Copy link
Member Author

Confirmed!
Capture d’écran, le 2019-05-10 à 12 47 38

@vincentsarago
Copy link
Member Author

closed by #106

@dionhaefner
Copy link

IIRC this was deliberate. We used to use the same resampling for the alpha mask, but it eroded the tile edges. E.g. linear resampling doesn't make much sense on a binary mask, does it?

@vincentsarago
Copy link
Member Author

@dionhaefner well I'm not sure how it does on a pure binary mask but at least when dealing with mask built from nodata it will mater.
Will need to test on pure alpha/binary mask

@dionhaefner
Copy link

When I played around with this, using resampling for the mask never had a positive effect. But YMMV

@vincentsarago vincentsarago reopened this May 14, 2019
@vincentsarago
Copy link
Member Author

Well it seems that this introduced a bug when dealing with internal mask (wonder why the tests didn't caught this)

When using bilinear resampling the mask is =255 everywhere

@vincentsarago
Copy link
Member Author

Well this is really strange I could not reproduce the bug (bilinear resampling of mask creating non-masked data) when using Rasterio wheels ... so I guess this has to deal with my gdal/numpy install 🤔 .

BUT I found that using something else than nearest resampling introduce mask artefacts ... I'm going to revert the change introduced in #106

I'm really sorry for the users that could have been impacted by the 1.2.6 release

@vincentsarago
Copy link
Member Author

Note: if we revert #106
this test :

tilesize = 128
arr, mask = utils.tile_read(address, bounds, tilesize, nodata=0)
masknodata = (arr[0] != 0).astype(np.uint8) * 255
np.testing.assert_array_equal(mask, masknodata)

fails which seems a bit strange. I'll investigate a bit more and might open an issue on rasterio

@vincentsarago
Copy link
Member Author

closed by d9e532a

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

Successfully merging a pull request may close this issue.

2 participants