EmguCV中的逐像素求和与减法 [英] Pixel-wise summation and subtraction in EmguCV

查看:251
本文介绍了EmguCV中的逐像素求和与减法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种优雅的方法来在EmguCV中执行逐像素求和和减法。



我正在尝试计算一个类似Haar的特征图片。
对于一维情况,可以通过将向量[xxxxxxxx]乘以以下向量逐个元素来完成:

  [1 -1 1 -1 1 -1 1 -1] 
[1 1 -1 -1 1 1 -1 -1]
[1 1 1 1 -1 -1 -1- 1]

所以我需要添加或减去图像的元素像素。



说,

  Bgr sum = new Bgr(); 
sum = sum + img [0,0]-img [0,1] + img [0,2]-img [0,3];

很显然,由于Bgr类中没有运算符 +,因此无法编译。我必须通过指定每个B,G,R值来创建一个新的Bgr,这很丑陋。



是否有执行优雅的逐像素运算的想法? / p>

上一个线程

解决方案

您可能会使用 img.GetSum()如果您首先翻转要减去的像素的符号。您可以通过将图像逐个元素地乘以由 1 -1 组成的矩阵来实现适当的地方。


I'm looking for an elegant way to perform pixel-wise summation and subtraction in EmguCV.

I'm trying to calculate the Haar-like features of an image. For a one-dimensional situation, it's done by multiplying the vector [x x x x x x x x] by the following vector element-wise:

[ 1 -1  1 -1  1 -1  1 -1]
[ 1  1 -1 -1  1  1 -1 -1]
[ 1  1  1  1 -1 -1 -1 -1]

So I need to add or subtract the element pixels of an image.

Say,

Bgr sum = new Bgr();
sum = sum + img[0,0] - img[0,1] + img[0,2] - img[0,3];

Obviously this won't compile since there's no operator "+" in class Bgr. I've to make a new Bgr by specifying each of the B, G, R value, which is ugly.

Any idea on performing elegant pixel-wise operation?

Previous Thread

解决方案

You could probably use img.GetSum() if you first flip the sign of the pixels you want to be subtracted. You might be able to do that by multiplying the image element-wise with a matrix consisting of 1 and -1 at the appropriate places.

这篇关于EmguCV中的逐像素求和与减法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆