Ask Your Question

Revision history [back]

Have i understood the OpenCV Mask Operation Example Formula Correctly

I have been looking at OpenCV and working through the tutorials. I have found myself at a point where i see the formula and i can't be sure of how to read it.

So i would like to know if my understanding of the formula on the following page is correct: http://docs.opencv.org/doc/tutorials/core/mat-mask-operations/mat-mask-operations.html

So to show my understanding i have implemented the formula in 3 ways, the first 2 are very close to the implementation found in the loop in the Sharpen method, the 3rd is presented as close to the second compact version of the formula as i could make it.

uchar zero = 0;

uchar cell_current = current[i];
uchar cell_previous = current[i - nChannels];
uchar cell_next = current[i + nChannels];

uchar cell_current_last_row = previous[i];
uchar cell_current_next_row = next[i];

uchar result = 5 * cell_current - (cell_previous + cell_next + cell_current_last_row + cell_current_next_row);
uchar result = 5 * cell_current - cell_previous - cell_next - cell_current_last_row - cell_current_next_row;

uchar result =
  zero     +     (-1 * cell_current_last_row)   +   zero
+ (-1 * cell_previous) + (5 * cell_current) + (-1 * cell_next)
+ zero     +     (-1 * cell_current_next_row)   +   zero

Finally any help / advise to clarify the question would be appreciated.