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

create a HSLtoRGB function for images #405

Open
12rambau opened this issue Dec 11, 2024 · 3 comments
Open

create a HSLtoRGB function for images #405

12rambau opened this issue Dec 11, 2024 · 3 comments

Comments

@12rambau
Copy link
Member

That's a request on Stack Exchange that was basically discarded by Noel.
I don't expect the math behind to change so I propose to hard code it in geetools: https://gis.stackexchange.com/questions/464403/how-to-convert-hsl-to-rgb-in-earth-engine-python

/**
 * Converts an HSV color value to RGB. Conversion formula
 * adapted from http://en.wikipedia.org/wiki/HSV_color_space.
 * Assumes h, s, and v are contained in the set [0, 1] and
 * returns r, g, and b in the set [0, 255].
 *
 * @param   Number  h       The hue
 * @param   Number  s       The saturation
 * @param   Number  v       The value
 * @return  Array           The RGB representation
 */
function hsvToRgb(h, s, v){
    var r, g, b;

    var i = Math.floor(h * 6);
    var f = h * 6 - i;
    var p = v * (1 - s);
    var q = v * (1 - f * s);
    var t = v * (1 - (1 - f) * s);

    switch(i % 6){
        case 0: r = v, g = t, b = p; break;
        case 1: r = q, g = v, b = p; break;
        case 2: r = p, g = v, b = t; break;
        case 3: r = p, g = q, b = v; break;
        case 4: r = t, g = p, b = v; break;
        case 5: r = v, g = p, b = q; break;
    }

    return [r * 255, g * 255, b * 255];
}.
@framunoz
Copy link
Contributor

But in this case, you want to have a function that, given an image in rgb, can be transformed in HSL (the requested one) and viceversa?

@fitoprincipe
Copy link
Member

I suppose he meant on the client-side, since ee.Image object has its own method already: ee.Image.rgbToHsv() and ee.Image.hsvToRgb()

@12rambau
Copy link
Member Author

sorry I made a mistake in the title it's HSL

@12rambau 12rambau changed the title create a HSVtoRGB function for images create a HSLtoRGB function for images Dec 18, 2024
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

No branches or pull requests

3 participants