Deleted all trailing whitespace.
This commit is contained in:
@@ -8,11 +8,11 @@ Mask operations on matrices are quite simple. The idea is that we recalculate ea
|
||||
Our test case
|
||||
=============
|
||||
|
||||
Let us consider the issue of an image contrast enhancement method. Basically we want to apply for every pixel of the image the following formula:
|
||||
Let us consider the issue of an image contrast enhancement 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)]
|
||||
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
|
||||
@@ -23,12 +23,12 @@ Let us consider the issue of an image contrast enhancement method. Basically we
|
||||
|
||||
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 putting 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 multiplied with the overlapped matrix values. It's the same thing, however in case of large matrices the latter notation is a lot easier to look over.
|
||||
|
||||
Now let us see how we can make this happen by using the basic pixel access method or by using the :filtering:`filter2D <filter2d>` function.
|
||||
Now let us see how we can make this happen by using the basic pixel access method or by using the :filtering:`filter2D <filter2d>` function.
|
||||
|
||||
The Basic Method
|
||||
================
|
||||
|
||||
Here's a function that will do this:
|
||||
Here's a function that will do this:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
@@ -49,7 +49,7 @@ Here's a function that will do this:
|
||||
|
||||
for(int i= nChannels;i < nChannels*(myImage.cols-1); ++i)
|
||||
{
|
||||
*output++ = saturate_cast<uchar>(5*current[i]
|
||||
*output++ = saturate_cast<uchar>(5*current[i]
|
||||
-current[i-nChannels] - current[i+nChannels] - previous[i] - next[i]);
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ We'll use the plain C [] operator to access pixels. Because we need to access mu
|
||||
|
||||
for(int i= nChannels;i < nChannels*(myImage.cols-1); ++i)
|
||||
{
|
||||
*output++ = saturate_cast<uchar>(5*current[i]
|
||||
*output++ = saturate_cast<uchar>(5*current[i]
|
||||
-current[i-nChannels] - current[i+nChannels] - previous[i] - next[i]);
|
||||
}
|
||||
}
|
||||
@@ -96,7 +96,7 @@ On the borders of the image the upper notation results inexistent pixel location
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
Result.row(0).setTo(Scalar(0)); // The top row
|
||||
Result.row(0).setTo(Scalar(0)); // The top row
|
||||
Result.row(Result.rows-1).setTo(Scalar(0)); // The bottom row
|
||||
Result.col(0).setTo(Scalar(0)); // The left column
|
||||
Result.col(Result.cols-1).setTo(Scalar(0)); // The right column
|
||||
@@ -108,19 +108,19 @@ Applying such filters are so common in image processing that in OpenCV there exi
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
Mat kern = (Mat_<char>(3,3) << 0, -1, 0,
|
||||
Mat kern = (Mat_<char>(3,3) << 0, -1, 0,
|
||||
-1, 5, -1,
|
||||
0, -1, 0);
|
||||
|
||||
Then call the :filtering:`filter2D <filter2d>` function specifying the input, the output image and the kernell to use:
|
||||
Then call the :filtering:`filter2D <filter2d>` function specifying the input, the output image and the kernell to use:
|
||||
|
||||
.. code-block:: cpp
|
||||
|
||||
filter2D(I, K, I.depth(), kern );
|
||||
filter2D(I, K, I.depth(), kern );
|
||||
|
||||
The function even has a fifth optional argument to specify the center of the kernel, and a sixth one for determining what to do in the regions where the operation is undefined (borders). Using this function has the advantage that it's shorter, less verbose and because there are some optimization techniques implemented it is usually faster than the *hand-coded method*. For example in my test while the second one took only 13 milliseconds the first took around 31 milliseconds. Quite some difference.
|
||||
|
||||
For example:
|
||||
For example:
|
||||
|
||||
.. image:: images/resultMatMaskFilter2D.png
|
||||
:alt: A sample output of the program
|
||||
@@ -128,7 +128,7 @@ For example:
|
||||
|
||||
You can download this source code from :download:`here <../../../../samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp>` or look in the OpenCV source code libraries sample directory at :file:`samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp`.
|
||||
|
||||
Check out an instance of running the program on our `YouTube channel <http://www.youtube.com/watch?v=7PF1tAU9se4>`_ .
|
||||
Check out an instance of running the program on our `YouTube channel <http://www.youtube.com/watch?v=7PF1tAU9se4>`_ .
|
||||
|
||||
.. raw:: html
|
||||
|
||||
|
Reference in New Issue
Block a user