2

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

4

1 回答 1

2

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.

于 2013-05-13T15:18:33.433 回答