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

fix for issue 647 #648

Merged
merged 4 commits into from Oct 19, 2023
Merged

fix for issue 647 #648

merged 4 commits into from Oct 19, 2023

Conversation

vincentsarago
Copy link
Member

This PR should closes #647

The main problem is that we are creating a WarpedVRT aligned with the desired bounds (to make sure we fetch the overview) but also with the output size, which result in the resampling_method having no effect because there is not downscaling/upscaling happening at read step.

To ✅ the solution we will need to add tests proving the resampling effects but also still make sure that we are fetching the overviews!!!

@vincentsarago vincentsarago marked this pull request as ready for review October 19, 2023 08:27
@vincentsarago
Copy link
Member Author

🥳 we already had tests to make sure we were fetching the right overview https://github.com/cogeotiff/rio-tiler/blob/main/tests/test_overview.py

I've added some and they are ✅ so we should be good to go 🚢

asset3 = os.path.join(os.path.dirname(__file__), "fixtures", "mosaic_cog3.tif")
asset1 = os.path.join(os.path.dirname(__file__), "fixtures", "mosaic_value_1.tif")
asset2 = os.path.join(os.path.dirname(__file__), "fixtures", "mosaic_value_2.tif")
asset3 = os.path.join(os.path.dirname(__file__), "fixtures", "mosaic_value_3.tif")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the assets to avoid resampling to have a role (because depending on GDAL versions the pixel values can slightly change)

src_dst, bounds, height, width, dst_crs=dst_crs
src_dst,
bounds,
dst_crs=dst_crs,
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now construct a VRT aligned with the reading bounds but which has the size defined by its projected resolution.

@vincentsarago
Copy link
Member Author

vincentsarago commented Oct 19, 2023

TODO

  • add tests to show the different resampling options have influence

@vincentsarago vincentsarago merged commit 880d275 into main Oct 19, 2023
7 checks passed
@vincentsarago vincentsarago deleted the issue647 branch October 19, 2023 15:35
@DanSchoppe
Copy link
Contributor

Awesome! Glad you got to the bottom of this @vincentsarago... not sure whether anyone else on earth would have had a chance 😅

@DanSchoppe
Copy link
Contributor

DanSchoppe commented Oct 19, 2023

@vincentsarago I pulled the newly released 6.2.4 into TiTiler and am seeing some wicked tile edge / border effects:

Before (rio-tiler 4.1.10, TiTiler 0.11.6)
image

After (rio-tiler 6.2.4, TiTiler 0.15.1)
image

Of course my test was not just testing changes from 6.2.3 -> 6.2.4, because of course 6.2.3 didn't have working resampling. The rio-tiler and TiTiler versions from the two test cases are listed.

Do you think this change is responsible?

@vincentsarago
Copy link
Member Author

😭

@vincentsarago
Copy link
Member Author

@DanSchoppe can you share how you created this?

@vincentsarago
Copy link
Member Author

vincentsarago commented Oct 19, 2023

😬 I see them too 😓

Screenshot 2023-10-19 at 9 20 53 PM

This is happening when we are overzooming (at zoom 17 it looks fine)

When you add padding=1 (not available by default in titiler, but in rio-tiler) it disappear

padding (int, optional): Padding to apply to each bbox edge. Helps reduce resampling artefacts along edges. Defaults to `0`.

@vincentsarago
Copy link
Member Author

I kinda think that's a better behaviour in general. what do you think?

Feel free to add padding in titiler 😅

we could also switch to nearest when doing upsampling https://github.com/DHI-GRAS/terracotta/blob/main/terracotta/raster.py#L361-L363

@DanSchoppe
Copy link
Contributor

When you add padding=1 (not available by default in titiler, but in rio-tiler) it disappear

I kinda think that's a better behaviour in general. what do you think?

This would fetch an extra pixel on each edge (eg. 258x258 resolution) to eliminate edge effects, correct? Are there any resampling algorithms that operate on a kernel larger than this padding (for example, would benefit from 260x260)?

Sure seems like default padding would be a great improvement, especially if 1px optimizes every resampling algorithm. Even when you're fetching just one tile, the padding would give you higher quality data near the edges.

@vincentsarago
Copy link
Member Author

This would fetch an extra pixel on each edge (eg. 258x258 resolution) to eliminate edge effects, correct?

yes

Are there any resampling algorithms that operate on a kernel larger than this padding (for example, would benefit from 260x260)?

I don't know

Sure seems like default padding would be a great improvement, especially if 1px optimizes every resampling algorithm.

It will only improve for non-nearest.

Even when you're fetching just one tile, the padding would give you higher quality data near the edges.

Changing the default from 0 to something else is a huge breaking change IMO.

This is something that could be set by default at titiler level 🤷

@DanSchoppe
Copy link
Contributor

It will only improve for non-nearest.

Even nearest might find that the padded pixel is actually nearer, right? So it'd benefit nearest as well.

Changing the default from 0 to something else is a huge breaking change IMO.

Oh, I was thinking the suggested change was to fetch with padding, perform any required operations (eg. resampling), then return a non-padded tile. If the suggestion was to return 258x258 tiles by default, that seems like a non-starter 😅

This is something that could be set by default at titiler level 🤷

That's fine for my personal needs, but leaving this tile edge artifact in rio-tiler seems pretty bad, doesn't it?

@vincentsarago
Copy link
Member Author

If the suggestion was to return 258x258 tiles by default, that seems like a non-starter

no, no. You suggested to set padding to something different than 0. with the padding option the output tile will always be 256 (the pixels are removed automatically)

I agree it might not be a big thing, but in some case having padding=1 or 2 might result in additional blocks to be fetched (and thus slow down the process) which is mostly why I think keeping 0 as default is a safer choice.

That's fine for my personal needs, but leaving this tile edge artifact in rio-tiler seems pretty bad, doesn't it?

the edges will be visible only in some case (mostly oversampling and for non-nearest resampling) so I feel rio-tiler is 👌 not setting default for the users.

@vincentsarago
Copy link
Member Author

We can start a new issue and see if other people have opinions! 🙏

@vincentsarago
Copy link
Member Author

On the bright side, rio-tiler is now two time faster 😱

Screenshot 2023-10-19 at 11 15 40 PM

@DanSchoppe
Copy link
Contributor

We can start a new issue and see if other people have opinions! 🙏

Sounds good!

On the bright side, rio-tiler is now two time faster 😱

🚀 Plus resampling is working again! 💯

Thanks @vincentsarago !

@vincentsarago
Copy link
Member Author

@DanSchoppe here is a small analysis of the impact of the resampling and padding https://gist.github.com/vincentsarago/ff73ea5dbf128949d951851cc8454b4f

the TLDR, padding is useful mostly when overzooming. When in the dataset's zoom range there is not highly visible edges so padding do not have huge impact.

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

Successfully merging this pull request may close these issues.

Reader resampling_method has no effect when doing Reprojection
2 participants