geotiffjs / geotiff.js

geotiff.js is a small library to parse TIFF files for visualization or analysis. It is written in pure JavaScript, and is usable in both the browser and node.js applications.
https://geotiffjs.github.io/
MIT License
859 stars 179 forks source link

how dow I read colur palette from a COG? #378

Open pitommasi opened 1 year ago

pitommasi commented 1 year ago

I need to display some COG using OpenLayers. So far I managed to do so but I had to specify the palette separately. Since the COG I'm using have the colormap already embedded (https://rasterio.readthedocs.io/en/latest/topics/color.html#writing-colormaps), I've been wondering whether there was a way to extract it dynamically from the COG instead of hardcoding it in the JS code.

DanielJDufour commented 1 year ago

Hello, you could try https://github.com/GeoTIFF/geotiff-palette and see if it helps in your use case?

pitommasi commented 1 year ago

Hi, thanks, I'll give it a go... I asked the same question there but didn't get a reply, hence, I've asked here :)

constantinius commented 1 year ago

The palette is stored in a TIFF Tag ColorMap.

We expose RGB reading using palettes in the GeoTIFF Image class and pass it to the fromPalette function. There is currently no predefined function to do so, but everything is accesible, I believe.

pitommasi commented 1 year ago

So I would I read the palette to pass it to a style? I mean, I know how to pass it to the style, eventually, but how do I retrieve it?

constantinius commented 1 year ago
image.fileDirectory.ColorMap
SlowMo24 commented 3 months ago

If your goal is to color your COG then the library already includes the required functionality if you use the readRGB function: https://github.com/geotiffjs/geotiff.js/blob/4af107db0b0a8b46213d444de924575b5c9255da/src/geotiffimage.js#L646

Note that if you use this library behind OpenLayers you may run into this issue: https://github.com/openlayers/openlayers/issues/15894