opencv特效处理
1 毛玻璃

#coding:utf-8
import cv2
import numpy as np#读取原始图像
src = cv2.imread('4.jpg')#新建目标图像
dst = np.zeros_like(src)#获取图像行和列
rows, cols = src.shape[:2]#定义偏移量和随机数
offsets = 5
random_num = 0#毛玻璃效果: 像素点邻域内随机像素点的颜色替代当前像素点的颜色
for y in range(rows - offsets):for x in range(cols - offsets):random_num = np.random.randint(0,offsets)dst[y,x] = src[y + random_num,x + random_num]#显示图像
cv2.imshow('src',src)
cv2.imshow('dst',dst)cv2.waitKey()
cv2.destroyAllWindows()


2 浮雕特效

# -*- coding: utf-8 -*-
import cv2
import numpy as np#读取原始图像
img = cv2.imread('4.jpg', 1)#获取图像的高度和宽度
height, width = img.shape[:2]#图像灰度处理
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)#创建目标图像
dstImg = np.zeros((height,width,1),np.uint8)#浮雕特效算法:newPixel = grayCurrentPixel - grayNextPixel + 150
for i in range(0,height):for j in range(0,width-1):grayCurrentPixel = int(gray[i,j])grayNextPixel = int(gray[i,j+1])newPixel = grayCurrentPixel - grayNextPixel + 150if newPixel > 255:newPixel = 255if newPixel < 0:newPixel = 0dstImg[i,j] = newPixel#显示图像
cv2.imshow('src', img)
cv2.imshow('dst',dstImg)#等待显示
cv2.waitKey()
cv2.destroyAllWindows()


3 油漆特效

# -*- coding: utf-8 -*-
import cv2
import numpy as np#读取原始图像
src = cv2.imread('4.jpg')#图像灰度处理
gray = cv2.cvtColor(src,cv2.COLOR_BGR2GRAY)#自定义卷积核
kernel = np.array([[-1,-1,-1],[-1,10,-1],[-1,-1,-1]])#图像浮雕效果
output = cv2.filter2D(gray, -1, kernel)#显示图像
cv2.imshow('Original Image', src)
cv2.imshow('Emboss_1',output)#等待显示
cv2.waitKey()
cv2.destroyAllWindows()


4 素描

#coding:utf-8
import cv2
import numpy as np#读取原始图像
img = cv2.imread('4.jpg')#图像灰度处理
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)#高斯滤波降噪
gaussian = cv2.GaussianBlur(gray, (5,5), 0)#Canny算子
canny = cv2.Canny(gaussian, 50, 150)#阈值化处理
ret, result = cv2.threshold(canny, 100, 255, cv2.THRESH_BINARY_INV)#显示图像
cv2.imshow('src', img)
cv2.imshow('result', result)
cv2.waitKey()
cv2.destroyAllWindows()


5 怀旧特效

#coding:utf-8
import cv2
import numpy as np#读取原始图像
img = cv2.imread('4.jpg')#获取图像行和列
rows, cols = img.shape[:2]#新建目标图像
dst = np.zeros((rows, cols, 3), dtype="uint8")#图像怀旧特效
for i in range(rows):for j in range(cols):B = 0.272*img[i,j][2] + 0.534*img[i,j][1] + 0.131*img[i,j][0]G = 0.349*img[i,j][2] + 0.686*img[i,j][1] + 0.168*img[i,j][0]R = 0.393*img[i,j][2] + 0.769*img[i,j][1] + 0.189*img[i,j][0]if B>255:B = 255if G>255:G = 255if R>255:R = 255dst[i,j] = np.uint8((B, G, R))#显示图像
cv2.imshow('src', img)
cv2.imshow('dst', dst)
cv2.waitKey()
cv2.destroyAllWindows()


6 光影特效

#coding:utf-8
import cv2
import math
import numpy as np#读取原始图像
img = cv2.imread('4.jpg')#获取图像行和列
rows, cols = img.shape[:2]#设置中心点
centerX = rows / 2
centerY = cols / 2
print(centerX, centerY)
radius = min(centerX, centerY)
print(radius)#设置光照强度
strength = 200#新建目标图像
dst = np.zeros((rows, cols, 3), dtype="uint8")#图像光照特效
for i in range(rows):for j in range(cols):#计算当前点到光照中心距离(平面坐标系中两点之间的距离)distance = math.pow((centerY-j), 2) + math.pow((centerX-i), 2)#获取原始图像B =  img[i,j][0]G =  img[i,j][1]R = img[i,j][2]if (distance < radius * radius):#按照距离大小计算增强的光照值result = (int)(strength*( 1.0 - math.sqrt(distance) / radius ))B = img[i,j][0] + resultG = img[i,j][1] + resultR = img[i,j][2] + result#判断边界 防止越界B = min(255, max(0, B))G = min(255, max(0, G))R = min(255, max(0, R))dst[i,j] = np.uint8((B, G, R))else:dst[i,j] = np.uint8((B, G, R))#显示图像
cv2.imshow('src', img)
cv2.imshow('dst', dst)
cv2.waitKey()
cv2.destroyAllWindows()


7 流年

#coding:utf-8
import cv2
import math
import numpy as np#读取原始图像
img = cv2.imread('4.jpg')#获取图像行和列
rows, cols = img.shape[:2]#新建目标图像
dst = np.zeros((rows, cols, 3), dtype="uint8")#图像流年特效
for i in range(rows):for j in range(cols):#B通道的数值开平方乘以参数12B = math.sqrt(img[i,j][0]) * 12G =  img[i,j][1]R =  img[i,j][2]if B>255:B = 255dst[i,j] = np.uint8((B, G, R))#显示图像
cv2.imshow('src', img)
cv2.imshow('dst', dst)
cv2.waitKey()
cv2.destroyAllWindows()

8 滤镜

#coding:utf-8
import cv2
import numpy as np#获取滤镜颜色
def getBGR(img, table, i, j):#获取图像颜色b, g, r = img[i][j]#计算标准颜色表中颜色的位置坐标x = int(g/4 + int(b/32) * 64)y = int(r/4 + int((b%32) / 4) * 64)#返回滤镜颜色表中对应的颜色return lj_map[x][y]#读取原始图像
img = cv2.imread('img.jpg')
lj_map = cv2.imread('5.png')#获取图像行和列
rows, cols = img.shape[:2]#新建目标图像
dst = np.zeros((rows, cols, 3), dtype="uint8")#循环设置滤镜颜色
for i in range(rows):for j in range(cols):dst[i][j] = getBGR(img, lj_map, i, j)#显示图像
cv2.imshow('src', img)
cv2.imshow('dst', dst)cv2.waitKey()
cv2.destroyAllWindows()

opencv图像处理学习相关推荐

  1. OpenCV 图像处理学习手册:1~5

    原文:Learning Image Processing with OpenCV 协议:CC BY-NC-SA 4.0 译者:飞龙 本文来自[ApacheCN 计算机视觉 译文集],采用译后编辑(MT ...

  2. opencv图像处理学习随笔:帮助文档运算公式中saturate的含义

    ☞ ░ 前往老猿Python博文目录 ░ 在opencv文档中中,加法运算的一种计算公式如下: dst(I)=saturate(src1(I)+src2(I))if mask(I)≠0 类似的公式还有 ...

  3. OpenCV图像处理学习二十,图像直方图均衡化原理与实现

    一.图像直方图的概念 图像直方图,是指对整个图像在灰度范围内的像素值(0~255)统计出现频率次数,据此生成的直方图,称为图像直方图.直方图反映了图像灰度的分布情况,是图像的统计学特征.图像的灰度直方 ...

  4. OpenCV图像处理学习九,双边滤波器 (Bilateral Filter)和中位数滤波器 (Median Filter)

    均值模糊无法克服边缘像素信息丢失缺陷,原因是均值滤波是基于平均权重,赋予图像内的像素与图像边缘像素一样的比值权重,图像处理是会使得边缘部分图像部分像素信息丢失: 高斯模糊部分克服了该缺陷,但是无法完全 ...

  5. OpenCV图像处理学习六,像素操作,使用line,ellipse,ellipse,rectangle,fillPoly函数绘制线、矩形、圆、椭圆等基本图形以及C++随机数产生器RNG的应用

    一.Point与Scalar 使用cv::Point与cv::Scalar Point表示2D平面上一个点x,y Point p; p.x = 10; p.y = 8; 或者 p = Pont(10, ...

  6. OpenCV图像处理学习十三,图像金字塔——高斯金字塔和拉普拉斯金字塔

    一.图像金字塔概念 我们在图像处理中常常会调整图像大小,最常见的就是放大(zoom in)和缩小(zoom out),尽管几何变换也可以实现图像放大和缩小,但是这里我们介绍图像金字塔 . 一个图像金字 ...

  7. OpenCV图像处理学习十八,霍夫变换实现交通车道线检测

    一.霍夫变换 经典霍夫变换用来检测图像中的直线,后来霍夫变换经过扩展可以进行任意形状物体的识别,例如圆和椭圆.霍夫变换运用两个坐标空间之间的变换,将在一个空间中具有相同形状的曲线或直线映射到另一个坐标 ...

  8. OpenCV图像处理学习四,像素的读写操作和图像反差函数操作

    一.读写图像 imread 可以指定加载为灰度或者RGB图像 Imwrite 保存图像文件,类型由扩展名决定 二.读写像素 读一个GRAY(灰度图)像素点的像素值(CV_8UC1) Scalar in ...

  9. opencv图像处理学习(二十六)——噪声

    1.噪声量化 图像噪声是图像在获取或传输的过程中受到随机信号干扰,妨碍人们对图像处理及分析处理的信号.很多时候将图像噪声看作多位随机过程,因而描述噪声的方法完全可以借用随机过程的描述,即使用其概率分布 ...

最新文章

  1. static关键字用法
  2. springBoot @Scheduled多任务同时开始执行
  3. svn错误:Two top-level reports with no target
  4. php 可以动态的new一个变量类名
  5. React 15.5带来重大修改
  6. web.xml与index.html
  7. 不动产中心考试计算机测试题,2005年全国计算机二级考试VFP笔试模拟题
  8. ecshop api.php,ecshop2.72 api.php 文件鸡肋注入
  9. 并查集 | 1107
  10. C语言随笔小算法:单项链表如何实现队列
  11. gcc/g++ 参数总结
  12. python 基础语法梳理
  13. TIA安装GSD文件
  14. 最常用的看板工具,敏捷开发工具
  15. three.js 05-08 之 TorusKnotGeometry 几何体
  16. lzg_ad: XPE操作系统镜像尺寸优化
  17. 中e管家理财小方法让闲钱变成活钱
  18. 内存池(memory pool)
  19. MVP结合(RecycleView,Retorfit,GreenDao和EventBus)数据展示
  20. 数字化时代已经改变了我们的沟通方式

热门文章

  1. 深入理解java虚拟机-第三版-周明志 Java虚拟机规范(java se 8) pdf
  2. 微信js 已经填写JS接口安全域名了,仍然报invalid url domain
  3. 统计系统技术方案-clickhouse
  4. 综合案例—Spark实时交易数据统计
  5. Sigfox融资1.5亿欧元扩展LPWA网络
  6. (数据结构基础)Among the following threaded binary trees (the threads are represented by dotted curves),……
  7. 计算机开机慢更新配置,系统开机慢?教你如何提高电脑开机速度!
  8. ps抠图基础篇:最常用的四种抠图方法
  9. 牛年第一瓜!阿里女员工被骗500多万!初中文化水平男子,滴滴开豪车,诈骗4000多万被判无期!...
  10. 社区项目发现的问题四 datatable的注意事项