openCV 学习笔记

基本图像处理:

图像分为单通道和多通道, 灰度图像每个 像素只需要一个字节表示, 是单通道图像, RGB图像每个像素需要3个字节表示, 是三通道图像.  

单通道图像的矩阵表示:

\newcommand{\tabItG}[1] { \textcolor{black}{#1} \cellcolor[gray]{0.8}}\begin{tabular} {ccccc}~ & \multicolumn{1}{c}{Column 0} &   \multicolumn{1}{c}{Column 1} &   \multicolumn{1}{c}{Column ...} & \multicolumn{1}{c}{Column m}\\Row 0 & \tabItG{0,0} & \tabItG{0,1} & \tabItG{...}  & \tabItG{0, m} \\Row 1 & \tabItG{1,0} & \tabItG{1,1} & \tabItG{...}  & \tabItG{1, m} \\Row ... & \tabItG{...,0} & \tabItG{...,1} & \tabItG{...} & \tabItG{..., m} \\Row n & \tabItG{n,0} & \tabItG{n,1} & \tabItG{n,...} & \tabItG{n, m} \\\end{tabular}

三通道图像的矩阵表示:

\newcommand{\tabIt}[1] { \textcolor{yellow}{#1} \cellcolor{blue} &  \textcolor{black}{#1} \cellcolor{green} & \textcolor{black}{#1} \cellcolor{red}}\begin{tabular} {ccccccccccccc}~ & \multicolumn{3}{c}{Column 0} &   \multicolumn{3}{c}{Column 1} &   \multicolumn{3}{c}{Column ...} & \multicolumn{3}{c}{Column m}\\Row 0 & \tabIt{0,0} & \tabIt{0,1} & \tabIt{...}  & \tabIt{0, m} \\Row 1 & \tabIt{1,0} & \tabIt{1,1} & \tabIt{...}  & \tabIt{1, m} \\Row ... & \tabIt{...,0} & \tabIt{...,1} & \tabIt{...} & \tabIt{..., m} \\Row n & \tabIt{n,0} & \tabIt{n,1} & \tabIt{n,...} & \tabIt{n, m} \\\end{tabular}


对图像的处理是每一个像素中的每一个通道值   遍历每个通道值的两种方法:

(这里是对加强图像对比度的处理, 其中arpha 是加强对比度的处理, beta是提高图像亮度的处理)

int channels = src.channels();     //读取通道值
	//每个像素的通道值可以归为列也可以归为行
	int Rows = src.rows * channels;    
	int Cols = src.cols;
	//如果图像是连续存储的, 就变为一行多列进行读取
	if (src.isContinuous()) {
		Cols *= Rows;
		Rows = 1;
	}

	uchar *p, *q;                      //行指针

	for (int i = 0; i < Rows; i++) {
		p = src.ptr<uchar>(i);
		q = res.ptr<uchar>(i);
		for (int j = 0; j < Cols; j++) {
			q[j] = saturate_cast<uchar>(alpha * p[j] + beta);  
		}
	}

for (int i = 0; i < src.rows; i++) {
		for (int j = 0; j < src.cols; j++) {
			for (int c = 0; c < 3; c++)
				res.at<Vec3b>(i, j)[c] = saturate_cast<uchar>(alpha * src.at<Vec3b>(i, j)[c] + beta);  //Vec3b表示三通道图像, 对每个通道进行处理
		}
	}

两种处理方法的复杂度相同, 都是需要对每个像素的每个通道分别处理     



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值