Pixel-wise summation and subtraction in EmguCV

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.


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.


  • Using numpy.unique on multiple columns of a pandas.DataFrame
  • Pygame trigonometry: Following the hypotenuse?
  • C#: override GetHashCode, what does this code do?
  • Want to multiply, not repeat variable
  • How to read csv file into an Array of arrays in scala
  • Doctrine DQL returning flat array from join
  • Fold function in Octave
  • Restrict mouse movement over a specified window handle
  • onpreviewframe byte[] to int[]
  • GMP Bit shift doesn't work on negative numbers
  • Timer once a minute on the minute
  • Extract decision boundary with scikit-learn linear SVM
  • Finding the number of elements less than or equal to k in a multiset
  • How to use the resource module to measure the running time of a function?
  • runtime-check whether an instance (Base*) override a parent function (Base::f())
  • cell spacing in div table
  • Is there a package like bigmemory in R that can deal with large list objects?
  • Java color detection
  • How can I enlarge video fullscreen without the affected interface project in as3?
  • C: Incompatible pointer type initializing
  • How to determine if there are bytes available to be read from boost:asio:serial_port
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • MVC3 Razor - ListBox pre-select not working
  • Python urlparse: small issue
  • FileReader+canvas image loading problem
  • Initializer list vs. initialization method
  • JavaScriptCore crash on iOS9
  • Weird JavaScript statement, what does it mean?
  • SVN: Merging two branches together
  • php design question - will a Helper help here?
  • Transpose CSV data with awk (pivot transformation)
  • KeystoneJS: Relationships in Admin UI not updating
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • JTable with a ScrollPane misbehaving
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • python draw pie shapes with colour filled
  • Django query for large number of relationships
  • UserPrincipal.Current returns apppool on IIS