Я проверил расчет почти 20 раз, и на расстоянии он выглядит правильно, что заставило меня задуматься, не сделал ли я что-то не так, переведя из numpy во встроенную математику, поскольку я не совсем привык к этому numpy.
Но, посмотрев документацию и основываясь на моем понимании, я тоже все сделал правильно. Поэтому я, возможно, что-то не понимаю.
Никакой разницы ни в numpy.radians, ни в math.radians, ни для sqrt, exp, sin, cos, hypot, fabs, pow или градусов, насколько я могу судить.
Где я не уверен, так это для np.select и np.where
Код: Выделить всё
def delta(color1=None, color2=None, WL=1, WC=2, WH=2):
'emulating colour.differences.delta_E_CIE2000'
L1,a1,b1 = (72.002334, 65.398518, -42.349132) #self.convert(typ, color1, 'Lab')
L2,a2,b2 = (0.0, 0.0, 0.0) #self.convert(typ, color2, 'Lab')
C1 = math.hypot(a1,b1)
C2 = math.hypot(a2,b2)
Cbar = (C1+C2)/2
Cbar7 = Cbar**7
G = 0.5*(1-math.sqrt(Cbar7/(Cbar7+25**7)))
ap1 = (1+G)*a1
ap2 = (1+G)*a2
Cp1 = math.hypot(ap1,b1)
Cp2 = math.hypot(ap2,b2)
if b1 == 0 and ap1 == 0:
hp1 = 0
else:
hp1 = math.degrees(math.atan2(b1,ap1))%360
if b2 == 0 and ap2 == 0:
hp2 = 0
else:
hp2 = math.degrees(math.atan2(b2,ap2))%360
dLp = L2 -L1
dCp = Cp2 - Cp1
hp2s1 = hp2 - hp1
Cp1m2 = Cp1*Cp2
if Cp1m2 == 0:
dH = 0
elif math.fabs(hp2s1) 180:
dH = hp2s1 - 360
elif hp2s1 < -180:
dH = hp2s1 +360
dH = 2*math.sqrt(Cp1m2)*math.sin(math.radians(dH/2))
LbarP = (L1+L2)/2
CbarP = (Cp1+Cp2)/2
ahp1s2 = math.fabs(hp1-hp2)
hp1a2 = hp1+hp2
if Cp1m2 == 0:
HbarP = hp1a2
elif ahp1s2 180 and hp1a2 < 360:
HbarP = (hp1a2 + 360) /2
elif ahp1s2 > 180 and hp1a2 >= 360:
HbarP = (hp1a2 - 360) /2
T = (
1
- 0.17 * math.cos(math.radians(HbarP-30))
+ 0.24 * math.cos(math.radians(2*HbarP))
+ 0.32 * math.cos(math.radians(3*HbarP+6))
- 0.20 * math.cos(math.radians(4*HbarP-63))
)
dT = 30*math.exp(-(((HbarP-275)/25)**2))
CbarP7 = CbarP**7
RC = 2*math.sqrt(CbarP7/(CbarP7+25**7))
LbarP2 = (LbarP-50)**2
SL = 1 + ((0.015*LbarP2)/math.sqrt(20+LbarP2))
SC = 1 + 0.045 * CbarP
SH = 1 + 0.015 * CbarP*T
RT = -math.sin(math.radians(2*dT))*RC
KL = WL
KC = WC
KH = WH
dE = math.sqrt(
(dLp/(KL*SL))**2
+ (dCp/(KC*SC))**2
+ (dH/(KH*SH))**2
+ RT*(dCp/(KC*SC))*(dH/(KH*SH))
)
return dE
Кто-нибудь видит, где я ошибся?
Подробнее здесь: https://stackoverflow.com/questions/798 ... lt-in-math
Мобильная версия