I need to collect some data from an image. Looping should be done with a mask.
For example, I have a simple cross mask:
1 1 1 1 1 And I need to know the sum of gray value of every point of Image.
I can use simple loops, like this:
// looping except first and last int nr = image.rows-1; int nc = image.cols-1; for (int j=1; j<nr; j++) { // for all rows const uchar* previous = image.ptr<const uchar>(j-1); // previous row const uchar* current = image.ptr<const uchar>(j); // current row const uchar* next = image.ptr<const uchar>(j+1); // next row for (int i=1; i<nc; i++) { sum = previos[i] + current[i] + current[i-1] + current[i+1] + next[i]; } } But I think I do this wrong. May be I should use something like cv::Mat kernel()?
I need mask to be a parameter, so I can use any kind of mask.
Is there a ready function for looping an image with a mask? ( There is filter2D function, but I don't need to make changes with an images, only some calculations with pixels ).
sumfor each pixel?