コード例 #1
0
def color_draw(path="img/sjtu.jpg", gammaS=1, gammaI=1):
    im = Image.open(path)

    if im.mode == 'RGB':
        ycbcr = im.convert('YCbCr')
        Iruv = np.ndarray((im.size[1], im.size[0], 3), 'u1', ycbcr.tobytes())
        type = "colour"
    else:
        Iruv = np.array(im)
        type = "black"

    S = get_s(Iruv[:, :, 0], gammaS=gammaS)
    T = get_t(Iruv[:, :, 0], type, gammaI=gammaI)
    Ypencil = S * T

    new_Iruv = Iruv.copy()
    new_Iruv.flags.writeable = True
    new_Iruv[:, :, 0] = Ypencil * 255

    R = cv2.cvtColor(new_Iruv, cv2.COLOR_YCR_CB2BGR)
    img = Image.fromarray(R)
    # img.show()

    name = path.rsplit("/")[-1].split(".")[0]
    suffix = path.rsplit("/")[-1].split(".")[1]

    # save_output(Image.fromarray(S * 255), name + "_s", suffix)
    # save_output(Image.fromarray(T * 255), name + "_t", suffix)
    save_output(img, name + "_color", suffix)
コード例 #2
0
ファイル: color_pencil.py プロジェクト: civilman628/myBegan
def color_draw(im, gammaS=1.5, gammaI=1):
    #im = Image.open(path)

    if im.mode == 'RGB':
        ycbcr = im.convert('YCbCr')
        Iruv = np.ndarray((im.size[1], im.size[0], 3), 'u1', ycbcr.tobytes())
        type = "colour"
    else:
        Iruv = np.array(im)
        type = "black"

    S = get_s(Iruv[:, :, 0], gammaS=gammaS)
    #T = get_t(Iruv[:, :, 0], type, gammaI=gammaI)
    Ypencil = S # S * T

    new_Iruv = Iruv.copy()
    new_Iruv.flags.writeable = True
    new_Iruv[:, :, 0] = Ypencil * 255

    colorpencil = Image.fromarray(new_Iruv,'YCbCr').convert('RGB')
    #R = cv2.cvtColor(new_Iruv,  cv2.COLOR_YCR_CB2BGR)
    #R = cv2.cvtColor(R,cv2.COLOR_BGR2RGB)
    #colorpencil = Image.fromarray(R)
    sketch = Image.fromarray(S * 255).convert('RGB')

    return colorpencil, sketch