Beispiel #1
0
def color_selection():
    color1=np.array((np.random.randint(256, size=3)),np.float16)
    print color1
    color1=color1/255
    
    color2=np.array((np.random.randint(256, size=3)),np.float16)
    print color2
    color2=color2/255
    
    print color1,color2
    
    '''To simulate
    '''
    
    color1_sim = np.matmul(cb_matrices["d"],np.matmul(rgb2lms,color1))
    # color1_sim = np.around(np.matmul(lms2rgb,color1_sim)*255)
    color1_sim = np.matmul(lms2rgb,color1_sim)
    
    color2_sim = np.matmul(cb_matrices["d"],np.matmul(rgb2lms,color2))
    # color1_sim = np.around(np.matmul(lms2rgb,color1_sim)*255)
    color2_sim = np.matmul(lms2rgb,color2_sim)
    
    print "color1_sim,color2_sim",color1_sim,color2_sim
    
    # color1=(color1[0],color1[1],color1[2])
    # color2=(color2[0],color2[1],color2[2])
    # color1= rgb2lab(color1)
    # color2= rgb2lab(color2)
    
    color1_lab=rgb2lab([[color1]])[0][0]
#     color1_lab=color1[0][0]
    color1_sim_lab=rgb2lab([[color1_sim]])[0][0]
#     color1_sim_lab=color1_sim[0][0]
    
    color2_lab=rgb2lab([[color2]])[0][0]
#     color2=color2[0][0]
    color2_sim_lab=rgb2lab([[color2_sim]])[0][0]
#     color2_sim=color2_sim[0][0]
    
    
    print color1_lab,"\n",color2_lab,"\n"
    
    # (color1[0],color1[1],color1[2])
    # color2=rgb2lab(color2[0],color2[1],color2[2])
    delta_E_rgb = delta_e.deltaE_cie76(color1_lab, color2_lab)
    delta_E_sim = delta_e.deltaE_cie76(color1_sim_lab, color2_sim_lab)
    
    # delta_e_cie1976(color1, color2)
    ratio_now = delta_E_rgb/delta_E_sim
    print delta_E_rgb,delta_E_sim
    print ratio_now
    
    return np.around(color1*255),np.around(color2*255),np.around(color1_sim*255),np.around(color2_sim*255),ratio_now
Beispiel #2
0
def test_cie76(dtype, channel_axis):
    data = load_ciede2000_data()
    N = len(data)
    lab1 = np.zeros((N, 3), dtype=dtype)
    lab1[:, 0] = data['L1']
    lab1[:, 1] = data['a1']
    lab1[:, 2] = data['b1']

    lab2 = np.zeros((N, 3), dtype=dtype)
    lab2[:, 0] = data['L2']
    lab2[:, 1] = data['a2']
    lab2[:, 2] = data['b2']

    lab1 = np.moveaxis(lab1, source=-1, destination=channel_axis)
    lab2 = np.moveaxis(lab2, source=-1, destination=channel_axis)
    dE2 = deltaE_cie76(lab1, lab2, channel_axis=channel_axis)
    assert dE2.dtype == _supported_float_type(dtype)
    oracle = np.array([
        4.00106328, 6.31415011, 9.1776999, 2.06270077, 2.36957073, 2.91529271,
        2.23606798, 2.23606798, 4.98000036, 4.9800004, 4.98000044, 4.98000049,
        4.98000036, 4.9800004, 4.98000044, 3.53553391, 36.86800781,
        31.91002977, 30.25309901, 27.40894015, 0.89242934, 0.7972, 0.8583065,
        0.82982507, 3.1819238, 2.21334297, 1.53890382, 4.60630929, 6.58467989,
        3.88641412, 1.50514845, 2.3237848, 0.94413208, 1.31910843
    ])
    rtol = 1e-5 if dtype == np.float32 else 1e-8
    assert_allclose(dE2, oracle, rtol=rtol)
Beispiel #3
0
def test_cie76():
    data = load_ciede2000_data()
    N = len(data)
    lab1 = np.zeros((N, 3))
    lab1[:, 0] = data['L1']
    lab1[:, 1] = data['a1']
    lab1[:, 2] = data['b1']

    lab2 = np.zeros((N, 3))
    lab2[:, 0] = data['L2']
    lab2[:, 1] = data['a2']
    lab2[:, 2] = data['b2']

    dE2 = deltaE_cie76(lab1, lab2)
    oracle = np.array([
        4.00106328, 6.31415011, 9.1776999, 2.06270077, 2.36957073, 2.91529271,
        2.23606798, 2.23606798, 4.98000036, 4.9800004, 4.98000044, 4.98000049,
        4.98000036, 4.9800004, 4.98000044, 3.53553391, 36.86800781,
        31.91002977, 30.25309901, 27.40894015, 0.89242934, 0.7972, 0.8583065,
        0.82982507, 3.1819238, 2.21334297, 1.53890382, 4.60630929, 6.58467989,
        3.88641412, 1.50514845, 2.3237848, 0.94413208, 1.31910843
    ])
    assert_allclose(dE2, oracle, rtol=1.e-8)
Beispiel #4
0
def test_single_color_cie76():
    lab1 = (0.5, 0.5, 0.5)
    lab2 = (0.4, 0.4, 0.4)
    deltaE_cie76(lab1, lab2)
def color_selection():
    color1 = np.array((np.random.randint(256, size=3)), np.float16)
    print color1
    color1 = color1 / 255

    color2 = np.array((np.random.randint(256, size=3)), np.float16)
    print color2
    color2 = color2 / 255

    print color1, color2
    color1_lab = rgb2lab([[color1]])[0][0]
    color2_lab = rgb2lab([[color2]])[0][0]

    print color1_lab, "\n", color2_lab, "\n"
    delta_E_rgb = delta_e.deltaE_cie76(color1_lab, color2_lab)
    '''To simulate d
    '''
    matrix_cvd = cb_matrices["d"]
    d_sim = {}
    d_sim['color1_sim'] = np.matmul(
        lms2rgb, np.matmul(matrix_cvd, np.matmul(rgb2lms, color1)))
    d_sim['color2_sim'] = np.matmul(
        lms2rgb, np.matmul(matrix_cvd, np.matmul(rgb2lms, color2)))

    print "color1_sim,color2_sim", d_sim['color1_sim'], d_sim['color2_sim']

    color1_sim_lab = rgb2lab([[d_sim['color1_sim']]])[0][0]
    color2_sim_lab = rgb2lab([[d_sim['color2_sim']]])[0][0]

    d_sim['delta_E_sim'] = delta_e.deltaE_cie76(color1_sim_lab, color2_sim_lab)

    d_sim['ratio_now'] = delta_E_rgb / d_sim['delta_E_sim']

    print d_sim
    print d_sim['ratio_now']
    '''To simulate d
    '''
    matrix_cvd = cb_matrices["p"]
    p_sim = {}
    p_sim['color1_sim'] = np.matmul(
        lms2rgb, np.matmul(matrix_cvd, np.matmul(rgb2lms, color1)))
    p_sim['color2_sim'] = np.matmul(
        lms2rgb, np.matmul(matrix_cvd, np.matmul(rgb2lms, color2)))

    print "color1_sim,color2_sim", p_sim['color1_sim'], p_sim['color2_sim']

    color1_sim_lab = rgb2lab([[p_sim['color1_sim']]])[0][0]
    color2_sim_lab = rgb2lab([[p_sim['color2_sim']]])[0][0]

    p_sim['delta_E_sim'] = delta_e.deltaE_cie76(color1_sim_lab, color2_sim_lab)

    p_sim['ratio_now'] = delta_E_rgb / p_sim['delta_E_sim']

    print p_sim
    print p_sim['ratio_now']
    '''To simulate t
    '''
    matrix_cvd = cb_matrices["t"]
    t_sim = {}
    t_sim['color1_sim'] = np.matmul(
        lms2rgb, np.matmul(matrix_cvd, np.matmul(rgb2lms, color1)))
    t_sim['color2_sim'] = np.matmul(
        lms2rgb, np.matmul(matrix_cvd, np.matmul(rgb2lms, color2)))

    print "color1_sim,color2_sim", t_sim['color1_sim'], t_sim['color2_sim']

    color1_sim_lab = rgb2lab([[t_sim['color1_sim']]])[0][0]
    color2_sim_lab = rgb2lab([[t_sim['color2_sim']]])[0][0]

    t_sim['delta_E_sim'] = delta_e.deltaE_cie76(color1_sim_lab, color2_sim_lab)

    t_sim['ratio_now'] = delta_E_rgb / t_sim['delta_E_sim']

    print t_sim
    print t_sim['ratio_now']

    return np.around(color1 * 255), np.around(color2 *
                                              255), d_sim, p_sim, t_sim