当前位置 博文首页 > 文章内容

    opencv - Glitch Art(RGB shift)

    作者: 栏目:未分类 时间:2020-07-20 11:00:58

    本站于2023年9月4日。收到“大连君*****咨询有限公司”通知
    说我们IIS7站长博客,有一篇博文用了他们的图片。
    要求我们给他们一张图片6000元。要不然法院告我们

    为避免不必要的麻烦,IIS7站长博客,全站内容图片下架、并积极应诉
    博文内容全部不再显示,请需要相关资讯的站长朋友到必应搜索。谢谢!

    另祝:版权碰瓷诈骗团伙,早日弃暗投明。

    相关新闻:借版权之名、行诈骗之实,周某因犯诈骗罪被判处有期徒刑十一年六个月

    叹!百花齐放的时代,渐行渐远!



      故障式艺术十分有趣,不过我了解不是太多,这篇仅实现了简单的 RGB shift。

      下面代码中我使用了保持 green 通道值不变 r 通道值向前偏移 8,b 通道值向后偏移 8。代码也没什么好说的地方,看到这类艺术图就能想到的简单算法(捂脸:

    import cv2 as cv
    import numpy as np
    
    
    im = cv.imread('../xxx')
    # im = np.clip(im, 0, 255)
    b, g, r = cv.split(im)
    r_im = np.zeros(im.shape, np.uint8)
    r_im[:, :, 2] = r
    g_im = np.zeros(im.shape, np.uint8)
    g_im[:, :, 1] = g
    b_im = np.zeros(im.shape, np.uint8)
    b_im[:, :, 0] = b
    n_im = np.zeros(im.shape, np.uint8)
    shift = 8
    for col in range(im.shape[0]):
        n_im[:, col, 0] = b[:, col + shift if col + shift < im.shape[0] else im.shape[0] - col - shift]
        if col > shift:
            n_im[:, col, 2] = r[:, col - shift]
        else:
            n_im[:, col, 2] = r[:, col]
        n_im[:, col, 1] = g[:, col]
    
    cv.imwrite('res.jpg', n_im)
    

      代码使用的原图:

      得到的结果: