user1196549
user1196549

Reputation:

How do I compute an averaged profile in OpenCV

I call an average profile the 1D signal obtained by averaging along the rows or columns in a rectangular image.

Px := Σ(y=1,H) I(x, y) / H

and

Py := Σ(x=1,W) I(x, y) / W

I couldn't find that in the API, maybe by not using the appropriate terminology.

I don't want a box filter, just one value per row/column. The sum instead of the average is equally good.

Upvotes: 1

Views: 349

Answers (1)

Luca
Luca

Reputation: 10996

You can use the reduce function: http://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#reduce

using namespace cv;

// Average over rows
Mat mean_over_rows; 
reduce(input_mat, mean_over_rows, 0, CV_REDUCE_AVG);
// Average over the columns
Mat mean_over_cols;
reduce(input_mat, mean_over_cols, 1, CV_REDUCE_AVG);

You can use the CV_REDUCE_SUM flag if you just want the summed projection along the desired axes.

Upvotes: 2

Related Questions