1、RGB ->灰度

#灰度   方式1
img=cv2.imread('b.png',0)
img1=cv2.imread('b.png',1)
height=img1.shape[0]
width=img1.shape[1]
print(img1.shape)
# cv2.imshow('rgb',img1)
# cv2.imshow('gray',img)
# cv2.waitKey(0)
#灰度 方式2
# dst=cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)#颜色空间转换
# cv2.imshow('gray1',dst)
# cv2.waitKey(0)
import numpy as np
#灰度 方式3
#RGB R=G=B=GRAY
# dst=np.zeros((height,width,3),np.uint8)
# for i in range(height):
# for j in range(width):
# (b,g,r)=img1[i,j]
# gray=(int(b)+int(g)+int(r))/3
# dst[i,j]=np.uint8(gray)
# cv2.imshow('dst',dst)
# cv2.waitKey(0) #灰度 方式4
# dst=np.zeros((height,width,3),np.uint8)
# for i in range(height):
# for j in range(width):
# (b,g,r)=img1[i,j]
# gray=int(b)*0.114+int(g)*0.587+int(r)*0.299
# dst[i,j]=np.uint8(gray)
# cv2.imshow('dst',dst)
# cv2.waitKey(0) #算法优化
# dst=np.zeros((height,width,3),np.uint8)
# for i in range(height):
# for j in range(width):
# (b,g,r)=img1[i,j]
# b=int(b)
# g=int(g)
# r=int(r)
# # gray=(b*1+g*2+r*1)/4#1+2+1=4 加的值越大越精确
# gray=(b*300+g*200+r*500)/1000
# dst[i,j]=gray
#
# cv2.imshow('优化',dst)
# cv2.waitKey(0)

2、颜色反转,底板效果

# # 灰度图片  255-px
# gray=cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)
# dst=np.zeros((height,width,1),np.uint8)
# for i in range(height):
# for j in range(width):
# dstpx=255-gray[i,j]
# dst[i,j]=dstpx
#
# cv2.imshow('dst',dst)
# cv2.waitKey(0)
# **************************
# RGB颜色反转
# dst=np.zeros((height,width,3),np.uint8)
# for i in range(height):
# for j in range(width):
# (b,g,r)=img1[i,j]
# dst[i,j]=[255-b,255-g,255-r]
#
# cv2.imshow('dst',dst)
# cv2.waitKey(0)

3、马赛克

# 马赛克
# dst=np.zeros((height,width,3),np.uint8)
# dst=img1
# for i in range(100,150):
# for j in range(50,150):
# if i%10==0 and j%10==0:
# for n in range(10):
# for m in range(10):
# print(img1[i,j])
# # (b,g,r)=img1[i,j]
# # dst[i+n,j+m]=(b,g,r)
# dst[i+n,j+m]=img1[i,j]
# cv2.imshow('masaike',dst)
# cv2.waitKey(0)

4、毛玻璃

# dst=np.zeros(img1.shape,np.uint8)
# 随机数范围mm
# mm=8
#
# for i in range(height):
# for j in range(width):
# index=int(random.random()*8)
# if i+8 < height and j+8 < width:
# dst[i,j]=img1[i+index,j+index]
# else:
# dst[i,j] = img1[i-index, j-index]
#
# cv2.imshow('maoboli',dst)
# cv2.waitKey(0)

5、图片融合

img=cv2.imread('a.jpg',1)
img=cv2.resize(img,(256,256)) roiH=int(height)
roiW=int(width)
# imgROI融合区域大小,两张图片一样大小
imgROI=img[0:roiH,0:roiW]
img1ROI=img1[0:roiH,0:roiW]
dst=np.zeros(img.shape,np.uint8) dst=cv2.addWeighted(imgROI,0.6,img1ROI,0.4,0) cv2.imshow('ss',dst)
cv2.waitKey(0)

6、边缘检测

img=cv2.imread('a.jpg',1)

#1 gray  2 高斯滤波 3 canny

gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# 高斯滤波 去除干扰像素
imgG=cv2.GaussianBlur(gray,(3,3),0)
# 图像卷积
dst1=cv2.Canny(img,50,50)
dst2=cv2.Canny(imgG,50,50)
cv2.imshow('dst2_meiyoulvbo',dst1)
cv2.imshow('lvbo',dst2)
cv2.waitKey(0)

7、浮雕效果

img=cv2.imread('b.png',1)
cv2.imshow('src',img)
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
dst=np.zeros((height,width,1),np.uint8)
for i in range(height):
for j in range(width-1):
dst[i,j]=gray[i,j]-gray[i,j+1]+150
if dst[i,j]>255:
dst[i,j]=255
if dst[i,j]<0:
dst[i, j]=0
cv2.imshow('dst',dst)
cv2.waitKey(0)

8、对比度

import cv2 as cv
img = cv.imread('3.jpg')
cv.imshow('src', img)
gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
cv.imshow('gray', gray)
# 对比度
clahe = cv.createCLAHE(clipLimit=5, tileGridSize=(8, 8))
dst = clahe.apply(gray)
cv.imshow('dst', dst)
cv.waitKey(0)

效果:

OpenCV 图像特效的更多相关文章

  1. 跟我学Python图像处理丨图像特效处理:毛玻璃、浮雕和油漆特效

    摘要:本文讲解常见的图像特效处理,从而让读者实现各种各样的图像特殊效果,并通过Python和OpenCV实现. 本文分享自华为云社区<[Python图像处理] 二十四.图像特效处理之毛玻璃.浮雕 ...

  2. OpenCV图像金字塔:高斯金字塔、拉普拉斯金字塔与图片尺寸缩放

    这篇已经写得很好,真心给作者点个赞.题目都是直接转过来的,直接去看吧. Reference Link : http://blog.csdn.net/poem_qianmo/article/detail ...

  3. Android 中的图像特效(Matrix)

    以前在线性代数中学习了矩阵,对矩阵的基本运算有一些了解,现在在Android中有一个Matrix类,它的中文意思就是矩阵.Matrix主要是用于图像的缩放.平移.旋转.扭曲等操作.图像处理,主要用到的 ...

  4. 【OpenCV新手教程之十三】OpenCV图像金字塔:高斯金字塔、拉普拉斯金字塔与图片尺寸缩放

    本系列文章由@浅墨_毛星云 出品,转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/26157633 作者:毛星云(浅墨) ...

  5. Opencv 图像叠加 添加水印

    Opencv 图像叠加 添加水印 C++: void Mat::copyTo(OutputArray m) const C++: void Mat::copyTo(OutputArray m, Inp ...

  6. opencv图像读取-imread

    前言 图像的读取和保存一定要注意imread函数的各个参数及其意义,尽量不要使用默认参数,否则就像数据格式出现错误(here)一样,很难查找错误原因的: re: 1.opencv图像的读取与保存; 完

  7. 学习 opencv---(12)OpenCV 图像金字塔:高斯金字塔,拉普拉斯金字塔与图片尺寸缩放

    在这篇文章里,我们一起学习下 图像金字塔 的一些基本概念,如何使用OpenCV函数pyrUp和pyrDown 对图像进行向上和向下采样,以及了解专门用于缩放图像尺寸的resize函数的用法.此博文一共 ...

  8. [OpenCV Qt教程] 在Qt图形界面中显示OpenCV图像的OpenGL Widget(第二部分)

    本文译自:http://www.robot-home.it/blog/en/software/tutorial-opencv-qt-opengl-widget-per-visualizzare-imm ...

  9. [OpenCV Qt教程] 在Qt图形界面中显示OpenCV图像的OpenGL Widget (第一部分)

    本文译自:http://www.robot-home.it/blog/en/software/tutorial-opencv-qt-opengl-widget-per-visualizzare-imm ...

随机推荐

  1. makemigrations migrate

    教程 如何重置迁移 (图片:https://www.pexels.com/photo/sky-flying-animals-birds-1209/) Django迁移系统的开发和优化使其能够进行大量迁 ...

  2. 全网最详细的PLSQL Developer + Oracle client的客户端 或者 PLSQL Developer + Oracle server服务端的下载与安装过程(图文详解)

    不多说,直接上干货! 环境说明: 本地没有安装Oracle服务端,oracle服务端64位,是远程连接,因此本地配置PLSQL Developer64位. Oracle database使用在本机部署 ...

  3. CNN网络架构演进

    卷积神经网络可谓是现在深度学习领域中大红大紫的网络框架,尤其在计算机视觉领域更是一枝独秀.CNN从90年代的LeNet开始,21世纪初沉寂了10年,直到12年AlexNet开始又再焕发第二春,从ZF ...

  4. PHP 编程小点

    1.全局变量,$global 2.引用.函数返回引用.写时拷贝.对象复制.clone.unset.$varname=null 3.函数作用域,但是没有块级作用域 4.php7 新特性 5.autolo ...

  5. CentOS7 apache

    1.准备环境 centos7最小化安装 yum安装wget.vim.gcc.gcc-c++.cmake 2.安装apache2.4.10 官网:http://httpd.apache.org/ 下载源 ...

  6. 长沙.NET社区之光

    奈何万事开头难 迎着改革开放四十年带来的春风,长沙的互联网生态环境以唐胡子俱乐部为首的一众互联网社群讲长沙互联网的环境推上了一个新的台阶.年底,我与有幸一起共事的溪源兄,下班后一起闲聊,觉着长沙的.N ...

  7. SQL服务器模式

    今天在执行这样一条语句时: SELECT store - freez AS less FROM `products`; 报如下错误: Data truncation: BIGINT UNSIGNED ...

  8. POJ 1007 DNA Sorting(sort函数的使用)

    Description One measure of ``unsortedness'' in a sequence is the number of pairs of entries that are ...

  9. [转]关于Linux安装mysql默认配置文件位置

    本文转自:https://blog.csdn.net/smile___you/article/details/54409073 在linux下面安装mysql如果在/etc下面没有存在my.cnf配置 ...

  10. ubuntu 上安装ssh

    1. 执行 sudo apt-get update 2. 安装 sudo apt-get install openssh-server 3.查看ssh服务状态 sudo service ssh sta ...