zoukankan      html  css  js  c++  java
  • opencv

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

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

    import cv2 as cv
    import numpy as np
    
    
    im = cv.imread('../xxx')
    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[1]):
        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)
    

      代码使用的原图:

      得到的结果:

  • 相关阅读:
    乐理学习
    hashtable
    vim配置
    SSH & Git
    Java实现单向链表反转
    Java实现二叉树遍历
    Mysql主从配置
    使用VirtualBox虚拟机搭建局域网
    Nginx配置try_files实践一
    Maven package打包webapp项目遇到的问题
  • 原文地址:https://www.cnblogs.com/darkchii/p/13343895.html
Copyright © 2011-2022 走看看