Closed DanielJDufour closed 2 years ago
I "think" YCbCr could be currently achieved by passing in a pixelValuesToColorFn that converts [Y, Cb, Cr] to "rgba(r, g, b, a)"
.
But it would be better to have georaster-layer-for-leaflet natively support this by creating this pixelValuesToColorFn if Photometric tag is YCBCR and no pixelValuesToColorFn is supplied.
@drwelby , could you provide a direct link to a YCbCr geotiff? I'll try to add an example visualizing YCbCr to https://github.com/geotiff/georaster-layer-for-leaflet-example once I got that. Thank you for brining this issue to our attention. I've just been reading up on YCbCr since then and it's fascinating stuff!
You and @m-mohr are too fast, I started writing out a feature request for this last night!
We've done it by supplying a pixelsValueToColorFn
:
function ycbcr2color (values){
const r = Math.round(values[0] + 1.40200 * (values[2] - 0x80));
const g = Math.round(values[0] - 0.34414 * (values[1] - 0x80) - 0.71414 * (values[2] - 0x80));
const b = Math.round(values[0] + 1.77200 * (values[1] - 0x80));
return `rgb(${r},${g},${b})`;
}
but had not gone to the point of making the detection automatic, or any other features like adding an option to force a color mode.
Here's a YCbCr COG for testing:
@drwelby , thank you. That is very helpful! I've added an example here: https://geotiff.github.io/georaster-layer-for-leaflet-example/examples/ycbcr.html
Updating georaster-layer-for-leaflet might be a bit tricky as I don't think the georaster dependency reveals this information. I'll try to see if there's an easy way to access the Photometric Interpretation metadata. Just curious, is photometric interpretation something that is stored in the STAC metadata? @m-mohr
Not that I'm aware of... Probably something that would need to be specified in the raster extension: https://github.com/stac-extensions/raster
We could certainly go in the direction of using STAC metadata for color interpretation if needed.
I can see PhotometricInterpretation: 6
in the IFDRequests
but it seems kind of clunky not to expose the other geotiff tags, such as how the geotransform is extracted.
I think I'll be able to add this with the following code:
if ((await georaster?._geotiff.getImage()).fileDirectory.PhotometricInterpretation === 6) {
pixelValuesToColorFn ??= function ycbcr2color (values){
const r = Math.round(values[0] + 1.40200 * (values[2] - 0x80));
const g = Math.round(values[0] - 0.34414 * (values[1] - 0x80) - 0.71414 * (values[2] - 0x80));
const b = Math.round(values[0] + 1.77200 * (values[1] - 0x80));
return `rgb(${r},${g},${b})`;
}
}
give me a day or two. the release process is rather lengthy with a lot of checks. this change should then percolate up to stac-layer and stac-browser.
Has this percolated yet? ☕
not yet, sir. I'll try to get to it this weekend. sorry.
A new version of GeoRasterLayer for Leaflet has been published that includes the YCbCr support. Thank you!
Thanks to you too!
Related: https://github.com/radiantearth/stac-browser/issues/108#issuecomment-994661736