You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have some rough, experimental code that finds the closest point in an RGB gamut to an out-of-gamut color, where 'closest' is defined by some distance metric i.e. CIEDE2000. It uses scipy.optimize.fmin_l_bfgs_b(), a optimizer which has support for simple box constraints.
Here is the code in its current rough state:
fromfunctoolsimportpartialimportcolourimportnumpyasnpfromscipyimportoptimizedefdelta_e(rgb1, rgb2):
"""Returns the CIEDE2000 difference between rgb1 and rgb2 (both sRGB with range 0-1). Reference: https://en.wikipedia.org/wiki/Color_difference#CIEDE2000."""lab1=colour.XYZ_to_Lab(colour.sRGB_to_XYZ(rgb1))
lab2=colour.XYZ_to_Lab(colour.sRGB_to_XYZ(rgb2))
returncolour.delta_E_CIE2000(lab1, lab2)
defopfunc_(x, loss, eps=1e-8):
"""Given a loss function i.e. delta_e(), returns the loss and gradient at a point x. The gradient is computed by finite difference."""grad=np.zeros_like(x)
eye=np.eye(len(x))
foriinrange(len(x)):
fx=loss(x)
grad[i] = (loss(x+eps*eye[i]) -fx) /epsreturnfx, graddefgamut_map(rgb):
"""Finds the nearest in-gamut color to an out-of-gamut color using delta_e() as its measure of difference."""x=np.clip(rgb, 0, 1)
if (rgb==x).all():
returnxloss=partial(delta_e, rgb)
opfunc=partial(opfunc_, loss=loss)
x, _, _=optimize.fmin_l_bfgs_b(opfunc, x, bounds=[(0, 1)]*3)
returnx
The text was updated successfully, but these errors were encountered:
I am definitely interested! :) This is a recurring convo topic, I had in mind to implement the ICC rendering intents (Absolute colorimetric, Relative colorimetric, Perceptual, Saturation) which was the purpose of this issue (even if empty): #154
I think we could stuff that in a new mapping sub-package at the root of colour.
I have some rough, experimental code that finds the closest point in an RGB gamut to an out-of-gamut color, where 'closest' is defined by some distance metric i.e. CIEDE2000. It uses scipy.optimize.fmin_l_bfgs_b(), a optimizer which has support for simple box constraints.
Here is the code in its current rough state:
The text was updated successfully, but these errors were encountered: