banesullivan / localtileserver

🌐 dynamic tile server for visualizing rasters in Jupyter with ipyleaflet or folium
https://localtileserver.banesullivan.com
MIT License
304 stars 29 forks source link

vmin and vmax #56

Closed giswqs closed 2 years ago

giswqs commented 2 years ago

How are vmin and vmax determined when plotting a single band with vmin=None and vmax=None? Are they derived from TileClient.metadata()["bands"] when users do not specify the values?

From the documentation, it seems vmin and vmax only support single-band imagery. How about multi-band imagery?

image

When plotting multi-band imagery using titiler, I use the percentile_2 and percentile_98 as the default vmin and vmax. https://github.com/giswqs/leafmap/blob/8bd65d9b42c0629d60b55f194d7e50ec04d9162a/leafmap/common.py#L979-L983

https://leafmap.org/notebooks/37_planetary_computer/ image

banesullivan commented 2 years ago

Most of this pertains to the upstream large_image package

How are vmin and vmax determined when plotting a single band with vmin=None and vmax=None?

They are determined with GDAL's GetStatistics() method directly: https://github.com/girder/large_image/blob/1b537a1fef5326721f2c8048361aba3d9f702656/sources/gdal/large_image_source_gdal/__init__.py#L522-L525

Check out GetStatistics()'s documentation for some additional features it provides

Are they derived from TileClient.metadata()["bands"] when users do not specify the values?

Exactly, yes

From the documentation, it seems vmin and vmax only support single-band imagery. How about multi-band imagery?

Hm, the documentation is lacking here for sure. These are actually supported for multi-band imagery. Here is an example:

from localtileserver import get_leaflet_tile_layer
from localtileserver import examples
from ipyleaflet import Map

tile_client = examples.get_san_francisco()

t = get_leaflet_tile_layer(tile_client, band=[1,2,3], palette=['r', 'g', 'b'], vmin=[0,0,0], vmax=[100,200,10])

m = Map(center=tile_client.center(), zoom=9)
m.add_layer(t)
m
Screen Shot 2022-01-08 at 11 41 58 AM

This scales each band in it's vmin/vmax range before mapping to the pallete for it's channel.


When plotting multi-band imagery using titiler, I use the percentile_2 and percentile_98 as the default vmin and vmax.

The percentile_* feature would be a great addition to large_image! Perhaps we should open a feature request there

giswqs commented 2 years ago

Thank you for the example. Great to know that it works multi-band imagery. I am implementing a GUI for loading raster in leafmap without coding.

https://user-images.githubusercontent.com/5016453/148656102-cff398f9-9eeb-4dc2-8974-9a35a2536a8e.mp4