opencv - Glitch Art(RGB shift)
最编程
2024-04-09 21:27:45
...
故障式艺术十分有趣,不过我了解不是太多,这篇仅实现了简单的 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)
代码使用的原图:
得到的结果:
原文地址:https://www.cnblogs.com/darkchii/p/13343895.html
上一篇: UniApp 向苹果商店发布应用程序指南
下一篇: c# Polygon 绘制多边形。