博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
OPENCV学习笔记2-6_简单的图像运算
阅读量:4619 次
发布时间:2019-06-09

本文共 1847 字,大约阅读时间需要 6 分钟。

  Images can be combined(结合) in different ways. Since they are regular(一般) matrices, they can be added, subtracted, multiplied, or divided.

1. Example analysis 

  可以使用cv::add函数来实现相加功能。如想得到加权和,可使用更精确的cv::addWeighted函数。

#include 
#include
#include
#include
using namespace cv;int main(){ Mat image1; Mat image2; image1 = imread("test.jpg"); image2 = imread("test_b.jpg"); namedWindow("Image 1"); imshow("Image 1", image1); namedWindow("Image 2"); imshow("Image 2", image2); Mat result; /* add two images: cvAddWeighted( const CvArr* src1, double alpha, const CvArr* src2, double beta, double gamma, CvArr* dst ); dst(I)=src1(I)*alpha+src2(I)*beta+gamma */ addWeighted(image1, 0.7, image2, 0.5, 0., result); namedWindow("result"); imshow("result", result); waitKey(); return 0;}

 1.2 Overloaded image operators(重载图像运算符)

  Most arithmetic functions(运算函数) have their corresponding operator(相应操作) overloaded in OpenCV 2. Consequently(因此), the call to cv::addWeighted can be written as follows:

  result = 0.7*image1 + 0.9*image2;

  The preceding(前面的) code is a more compact form(紧凑的形式) that is also easier to read.

1.3 Splitting the image channels(分割图像通道)

  use the cv::split function that will copy the three channels of a color image into three distinct(不同) cv::Mat instances(实例). Suppose we want to add our rain image to the blue channel only. The following is how we would proceed:

  // create vector of 3 images

  std::vector<cv::Mat> planes;

  // split 1 3-channel image into 3 1-channel images

  cv::split(image1, planes);

  // add to blue channel

  planes[0] += image2;

  // merge the 3 1-channel images into 1 3-channel image

  cv::merge(planes, result);

 

转载于:https://www.cnblogs.com/yunfung/p/7560901.html

你可能感兴趣的文章
connection string for Excel/Access 2010
查看>>
【转】【Python】Python中的__init__.py与模块导入(from import 找不到模块的问题)
查看>>
学习wavenet_vocoder之环境配置
查看>>
常用Maven命令
查看>>
Docker启动mysql的坑2
查看>>
j2ee爬坑行之二 servlet
查看>>
JAVA基础入门(JDK、eclipse下载安装)
查看>>
最基础的applet运用--在applet上画线
查看>>
并不对劲的hdu4777
查看>>
linux使用rz、sz快速上传、下载文件
查看>>
判断数字的正则表达式
查看>>
DOC常用命令(转)
查看>>
php写一个判断是否有cookie的脚本
查看>>
Mac配置Fiddler抓包工具
查看>>
转:Java并发集合
查看>>
Word截图PNG,并压缩图片大小
查看>>
Python项目对接CAS方案
查看>>
mysql产生随机数
查看>>
编程风格
查看>>
熟悉常用的Linux命令
查看>>