Page 1 of 1

Color Conversion - RGB to HSV and back... (almost)

Posted: Thu Apr 13, 2017 11:04 pm
by capellan
Hi All,

Download this GUI Stack for Scott Raney's Color Conversion Functions:
RGB to HSV and HSV to RGB.

Only for certain colors this is a lossy conversion: Once you convert some
RGB colors to HSV, the function HSVtoRGB does not restore them back
exactly as before.
Does anyone knows (or have created) a pair of RGBtoHSV and HSVtoRGB
color conversion functions that do not lose or change color information?

Thanks in advance!

Al
LC6_Convert_RGB_to_HSV_and_back_screenshot.PNG
Screenshot of stack "RGB to HSV and back"
LC6_Convert_RGB_to_HSV_and_back.zip
Stack "RGB to HSV and back"
(1.92 KiB) Downloaded 77 times

Re: Color Conversion - RGB to HSV and back... (almost)

Posted: Fri Apr 14, 2017 4:37 am
by [-hh]
Alejandro,

the problem is here the integer rounding.

An integer RGB triple converts correctly to HSV/HSL expressed as floats.
You can then go back 'exactly' (if the floats are exact enough) to RGB.

But obviously you can't go back from the HSV/HSL floats _changed to integer_ to the same RGB. The error will usually be within plus/minus 1 of 255.

H.

Re: Color Conversion - RGB to HSV and back... (almost)

Posted: Fri Apr 14, 2017 6:32 am
by capellan
I understand. Then, I just need to change a single number in this script:

Change the script of button "HSV to RGB" from this:
if the number of lines of fld 2 = 2 then
put line 2 of fld 2 into w

To this:
if the number of lines of fld 2 = 2 then
put line 1 of fld 2 into w

Many thanks for pointing this! :)

Al