#!/usr/bin/env python |
# encoding: utf-8 |
''' |
python图片转换 特效 时光滤镜 旧照片滤镜 |
''' |
import cv2, math |
import numpy as np |
class picture: |
def __init__( self ): |
self .path = 'assets/picture.jpeg' |
def hello( self ): |
return self |
def run( self ): |
# 读取原始图像 |
img = cv2.imread( self .path) |
# 获取图像行和列 |
rows, cols = img.shape[: 2 ] |
# 新建目标图像 |
dst = np.zeros((rows, cols, 3 ), dtype = "uint8" ) |
# 图像流年特效 |
for i in range (rows): |
for j in range (cols): |
# B通道的数值开平方乘以参数12 |
B = math.sqrt(img[i, j][ 0 ]) * 12 |
G = img[i, j][ 1 ] |
R = img[i, j][ 2 ] |
if B > 255 : |
B = 255 |
dst[i, j] = np.uint8((B, G, R)) |
# 显示图像 |
cv2.imshow( 'src' , img) |
cv2.imshow( 'dst' , dst) |
cv2.waitKey() |
cv2.destroyAllWindows() |
if __name__ = = '__main__' : |
picture().hello().run() |