文章图片
在medium上看到一篇介绍opencv滤镜效果的博客,这里做一下记录和分享.
卷积操作
文章图片
【计算机视觉知识点|OpenCV滤镜效果】高斯模糊
pip3 install opencv-python
pip3 install scipydef gaussianBlur(image):
return cv2.GaussianBlur(image, (35, 35), 0)initialImage = cv2.imread("image1.jpg")
blurredImage = gaussianBlur(copy.deepcopy(initialImage))
cv2.imwrite("blurred.jpg", blurredImage)
文章图片
锐化
def sharpen(image):
kernel = np.array([[-1, -1, -1], [-1, 9, -1], [-1, -1, -1]])
return cv2.filter2D(image, -1, kernel)
文章图片
Sepia
def sepia(image):
kernel = np.array([[0.272, 0.534, 0.131],
[0.349, 0.686, 0.168],
[0.393, 0.769, 0.189]])
return cv2.filter2D(image, -1, kernel)
文章图片
emboss
def emboss(image):
kernel = np.array([[0,-1,-1],
[1,0,-1],
[1,1,0]])
return cv2.filter2D(image, -1, kernel)
文章图片
像素操作
def brightnessControl(image, level):
return cv2.convertScaleAbs(image, beta=level)
文章图片
查找表操作
def spreadLookupTable(x, y):
spline = UnivariateSpline(x, y)
return spline(range(256))
def warmImage(image):
increaseLookupTable = spreadLookupTable([0, 64, 128, 256], [0, 80, 160, 256])
decreaseLookupTable = spreadLookupTable([0, 64, 128, 256], [0, 50, 100, 256])
red_channel, green_channel, blue_channel = cv2.split(image)
red_channel = cv2.LUT(red_channel, increaseLookupTable).astype(np.uint8)
blue_channel = cv2.LUT(blue_channel, decreaseLookupTable).astype(np.uint8)
return cv2.merge((red_channel, green_channel, blue_channel))
def coldImage(image):
increaseLookupTable = spreadLookupTable([0, 64, 128, 256], [0, 80, 160, 256])
decreaseLookupTable = spreadLookupTable([0, 64, 128, 256], [0, 50, 100, 256])
red_channel, green_channel, blue_channel = cv2.split(image)
red_channel = cv2.LUT(red_channel, decreaseLookupTable).astype(np.uint8)
blue_channel = cv2.LUT(blue_channel, increaseLookupTable).astype(np.uint8)
return cv2.merge((red_channel, green_channel, blue_channel))
暖色调效果
文章图片
冷色调
文章图片
推荐阅读
- C++基础|opencv学习笔记(1)
- 技术交流|详解用OpenCV绘制各类几何图形
- python|用Python写个自动批改作业系统
- 深度学习|在Android上部署TF目标检测模型
- python-opencv|opencv缩放
- 图像处理|5分钟学会,使用opencv进行基本的图像操作—读、写、显示、缩放、裁剪(python语言)
- ubuntu|Ubuntu18.04安装opencv3.4.1+opencv_contrib3.4.1
- opencv|opencv.js 之官网教程翻译加代码
- 计算机视觉|Opencv 基于C++识别绿灯