Commit 61a40ddf authored by Andrey Kamaev's avatar Andrey Kamaev Committed by OpenCV Buildbot

Merge pull request #186 from vpisarev:doc_fixes_master

parents 5c2d5906 70c409f0
...@@ -11,17 +11,15 @@ In this tutorial you will learn how to: ...@@ -11,17 +11,15 @@ In this tutorial you will learn how to:
.. container:: enumeratevisibleitemswithsquare .. container:: enumeratevisibleitemswithsquare
+ Access pixel values + Access pixel values
+ Initialize a matrix with zeros + Initialize a matrix with zeros
+ Learn what :saturate_cast:`saturate_cast <>` does and why it is useful + Learn what :saturate_cast:`saturate_cast <>` does and why it is useful
+ Get some cool info about pixel transformations + Get some cool info about pixel transformations
Theory Theory
======= =======
.. note:: .. note::
The explanation below belongs to the book `Computer Vision: Algorithms and Applications <http://szeliski.org/Book/>`_ by Richard Szeliski The explanation below belongs to the book `Computer Vision: Algorithms and Applications <http://szeliski.org/Book/>`_ by Richard Szeliski
Image Processing Image Processing
...@@ -38,7 +36,7 @@ Image Processing ...@@ -38,7 +36,7 @@ Image Processing
Pixel Transforms Pixel Transforms
^^^^^^^^^^^^^^^^^ -----------------
.. container:: enumeratevisibleitemswithsquare .. container:: enumeratevisibleitemswithsquare
...@@ -47,7 +45,7 @@ Pixel Transforms ...@@ -47,7 +45,7 @@ Pixel Transforms
* Examples of such operators include *brightness and contrast adjustments* as well as color correction and transformations. * Examples of such operators include *brightness and contrast adjustments* as well as color correction and transformations.
Brightness and contrast adjustments Brightness and contrast adjustments
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ------------------------------------
.. container:: enumeratevisibleitemswithsquare .. container:: enumeratevisibleitemswithsquare
...@@ -70,9 +68,7 @@ Brightness and contrast adjustments ...@@ -70,9 +68,7 @@ Brightness and contrast adjustments
Code Code
===== =====
.. container:: enumeratevisibleitemswithsquare * The following code performs the operation :math:`g(i,j) = \alpha \cdot f(i,j) + \beta` :
* The following code performs the operation :math:`g(i,j) = \alpha \cdot f(i,j) + \beta` :
.. code-block:: cpp .. code-block:: cpp
...@@ -87,38 +83,37 @@ Code ...@@ -87,38 +83,37 @@ Code
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
/// Read image given by user /// Read image given by user
Mat image = imread( argv[1] ); Mat image = imread( argv[1] );
Mat new_image = Mat::zeros( image.size(), image.type() ); Mat new_image = Mat::zeros( image.size(), image.type() );
/// Initialize values /// Initialize values
std::cout<<" Basic Linear Transforms "<<std::endl; std::cout<<" Basic Linear Transforms "<<std::endl;
std::cout<<"-------------------------"<<std::endl; std::cout<<"-------------------------"<<std::endl;
std::cout<<"* Enter the alpha value [1.0-3.0]: ";std::cin>>alpha; std::cout<<"* Enter the alpha value [1.0-3.0]: ";std::cin>>alpha;
std::cout<<"* Enter the beta value [0-100]: "; std::cin>>beta; std::cout<<"* Enter the beta value [0-100]: "; std::cin>>beta;
/// Do the operation new_image(i,j) = alpha*image(i,j) + beta /// Do the operation new_image(i,j) = alpha*image(i,j) + beta
for( int y = 0; y < image.rows; y++ ) for( int y = 0; y < image.rows; y++ ) {
{ for( int x = 0; x < image.cols; x++ ) for( int x = 0; x < image.cols; x++ ) {
{ for( int c = 0; c < 3; c++ ) for( int c = 0; c < 3; c++ ) {
{ new_image.at<Vec3b>(y,x)[c] =
new_image.at<Vec3b>(y,x)[c] = saturate_cast<uchar>( alpha*( image.at<Vec3b>(y,x)[c] ) + beta );
saturate_cast<uchar>( alpha*( image.at<Vec3b>(y,x)[c] ) + beta ); }
} }
}
} }
/// Create Windows /// Create Windows
namedWindow("Original Image", 1); namedWindow("Original Image", 1);
namedWindow("New Image", 1); namedWindow("New Image", 1);
/// Show stuff /// Show stuff
imshow("Original Image", image); imshow("Original Image", image);
imshow("New Image", new_image); imshow("New Image", new_image);
/// Wait until user press some key /// Wait until user press some key
waitKey(); waitKey();
return 0; return 0;
} }
Explanation Explanation
...@@ -155,13 +150,14 @@ Explanation ...@@ -155,13 +150,14 @@ Explanation
.. code-block:: cpp .. code-block:: cpp
for( int y = 0; y < image.rows; y++ ) for( int y = 0; y < image.rows; y++ ) {
{ for( int x = 0; x < image.cols; x++ ) for( int x = 0; x < image.cols; x++ ) {
{ for( int c = 0; c < 3; c++ ) for( int c = 0; c < 3; c++ ) {
{ new_image.at<Vec3b>(y,x)[c] = new_image.at<Vec3b>(y,x)[c] =
saturate_cast<uchar>( alpha*( image.at<Vec3b>(y,x)[c] ) + beta ); } saturate_cast<uchar>( alpha*( image.at<Vec3b>(y,x)[c] ) + beta );
} }
} }
}
Notice the following: Notice the following:
...@@ -209,6 +205,6 @@ Result ...@@ -209,6 +205,6 @@ Result
* We get this: * We get this:
.. image:: images/Basic_Linear_Transform_Tutorial_Result_0.jpg .. image:: images/Basic_Linear_Transform_Tutorial_Result_0.jpg
:alt: Basic Linear Transform - Final Result :alt: Basic Linear Transform - Final Result
:align: center :align: center
...@@ -39,7 +39,7 @@ Morphological Operations ...@@ -39,7 +39,7 @@ Morphological Operations
:align: center :align: center
Dilation Dilation
^^^^^^^^^ ~~~~~~~~
* This operations consists of convoluting an image :math:`A` with some kernel (:math:`B`), which can have any shape or size, usually a square or circle. * This operations consists of convoluting an image :math:`A` with some kernel (:math:`B`), which can have any shape or size, usually a square or circle.
...@@ -54,7 +54,7 @@ Dilation ...@@ -54,7 +54,7 @@ Dilation
The background (bright) dilates around the black regions of the letter. The background (bright) dilates around the black regions of the letter.
Erosion Erosion
^^^^^^^^ ~~~~~~~
* This operation is the sister of dilation. What this does is to compute a local minimum over the area of the kernel. * This operation is the sister of dilation. What this does is to compute a local minimum over the area of the kernel.
...@@ -216,17 +216,17 @@ Explanation ...@@ -216,17 +216,17 @@ Explanation
.. code-block:: cpp .. code-block:: cpp
Mat element = getStructuringElement( erosion_type, Mat element = getStructuringElement( erosion_type,
Size( 2*erosion_size + 1, 2*erosion_size+1 ), Size( 2*erosion_size + 1, 2*erosion_size+1 ),
Point( erosion_size, erosion_size ) ); Point( erosion_size, erosion_size ) );
We can choose any of three shapes for our kernel: We can choose any of three shapes for our kernel:
.. container:: enumeratevisibleitemswithsquare .. container:: enumeratevisibleitemswithsquare
+ Rectangular box: MORPH_RECT + Rectangular box: MORPH_RECT
+ Cross: MORPH_CROSS + Cross: MORPH_CROSS
+ Ellipse: MORPH_ELLIPSE + Ellipse: MORPH_ELLIPSE
Then, we just have to specify the size of our kernel and the *anchor point*. If not specified, it is assumed to be in the center. Then, we just have to specify the size of our kernel and the *anchor point*. If not specified, it is assumed to be in the center.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment