opencv/doc/tutorials/core/mat-mask-operations/mat-mask-operations.rst
Bernat Gabor a2975f337a 1) Converted all images to JPG to reduce size.
2) Added a raw Latex page break directive after each TOC tree. (For the PDF tutorial look).
3) Two finished tutorials: 
   a) one describing how the Mat data structure works and its output capabilities (format function) (demonstration YouTube video included).
   b) one describing image scanning operations plus the LUT function (demonstration YouTube video included). 
   c) a basic filtering approach (plus multi row image scanning demonstration) in the work.
2011-07-19 22:08:54 +00:00

25 lines
1.3 KiB
ReStructuredText

.. _maskOperations:
Mask operations on matrixes
***************************
Mask operations on matrixes are quite simple. The idea is that we recalculate each pixels value in an image according to a matrix mask. This mask holds values that will just how much influence have neighbor pixel values (and the pixel value itself) to the new pixel value. From a mathematical point of view we make a weighted average, with our specified values.
Our test case
=============
Let us consider the issue of an image contrast enchancement method. Basically we want to apply for every pixel of the image the following formula:
.. math::
I(i,j) = 5*I(i,j) - [ I(i-1,j) + I(i+1,j) + I(i,j-1) + I(i,j+1)]
\iff I(i,j)*M, \text{where }
M = \bordermatrix{ _i\backslash ^j & -1 & 0 & -1 \cr
-1 & 0 & -1 & 0 \cr
0 & -1 & 5 & -1 \cr
+1 & 0 & -1 & 0 \cr
}
The first notation is by using a formula, while the second is a compacted version of the first by using a mask. You use the mask by puting the center of the mask matrix (in the upper case noted by the zero-zero index) on the pixel you want to calculate and sum up the pixel values multiplicated with the overlapped matrix values. It's the same thing, however in case of large matrices the later notation is a lot easier to look over.