11Smoothing Images {#tutorial_gausian_median_blur_bilateral_filter}
22================
33
4+ @next_tutorial{tutorial_erosion_dilatation}
5+
46Goal
57----
68
79In this tutorial you will learn how to apply diverse linear filters to smooth images using OpenCV
810functions such as:
911
10- - @ ref cv:: blur
11- - @ ref cv:: GaussianBlur
12- - @ ref cv:: medianBlur
13- - @ ref cv:: bilateralFilter
12+ - ** blur() **
13+ - ** GaussianBlur() **
14+ - ** medianBlur() **
15+ - ** bilateralFilter() **
1416
1517Theory
1618------
9294 - Loads an image
9395 - Applies 4 different kinds of filters (explained in Theory) and show the filtered images
9496 sequentially
97+
98+ @add_toggle_cpp
99+ - ** Downloadable code** : Click
100+ [ here] ( https://raw.githubusercontent.com/opencv/opencv/master/samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp )
101+
102+ - ** Code at glance:**
103+ @include samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp
104+ @end_toggle
105+
106+ @add_toggle_java
95107- ** Downloadable code** : Click
96- [ here] ( https://github.com/opencv/opencv/tree/master/samples/cpp/tutorial_code/ImgProc/Smoothing.cpp )
108+ [ here] ( https://raw.githubusercontent.com/opencv/opencv/master/samples/java/tutorial_code/ImgProc/Smoothing/Smoothing.java )
109+
110+ - ** Code at glance:**
111+ @include samples/java/tutorial_code/ImgProc/Smoothing/Smoothing.java
112+ @end_toggle
113+
114+ @add_toggle_python
115+ - ** Downloadable code** : Click
116+ [ here] ( https://raw.githubusercontent.com/opencv/opencv/master/samples/python/tutorial_code/imgProc/Smoothing/smoothing.py )
117+
97118- ** Code at glance:**
98- @include samples/cpp/tutorial_code/ImgProc/Smoothing.cpp
119+ @include samples/python/tutorial_code/imgProc/Smoothing/smoothing.py
120+ @end_toggle
99121
100122Explanation
101123-----------
102124
103- -# Let's check the OpenCV functions that involve only the smoothing procedure, since the rest is
104- already known by now.
105- -# ** Normalized Block Filter:**
125+ Let's check the OpenCV functions that involve only the smoothing procedure, since the rest is
126+ already known by now.
106127
107- OpenCV offers the function @ref cv::blur to perform smoothing with this filter.
108- @snippet cpp/tutorial_code/ImgProc/Smoothing.cpp blur
128+ #### Normalized Block Filter:
109129
130+ - OpenCV offers the function ** blur()** to perform smoothing with this filter.
110131 We specify 4 arguments (more details, check the Reference):
111-
112132 - * src* : Source image
113133 - * dst* : Destination image
114- - *Size( w,h )*: Defines the size of the kernel to be used ( of width *w* pixels and height
134+ - * Size( w, h )* : Defines the size of the kernel to be used ( of width * w* pixels and height
115135 * h* pixels)
116136 - * Point(-1, -1)* : Indicates where the anchor point (the pixel evaluated) is located with
117137 respect to the neighborhood. If there is a negative value, then the center of the kernel is
118138 considered the anchor point.
119139
120- -# ** Gaussian Filter:**
140+ @add_toggle_cpp
141+ @snippet cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp blur
142+ @end_toggle
121143
122- It is performed by the function @ref cv::GaussianBlur :
123- @snippet cpp/tutorial_code/ImgProc/Smoothing.cpp gaussianblur
144+ @add_toggle_java
145+ @snippet samples/java/tutorial_code/ImgProc/Smoothing/Smoothing.java blur
146+ @end_toggle
124147
125- Here we use 4 arguments (more details, check the OpenCV reference):
148+ @add_toggle_python
149+ @snippet samples/python/tutorial_code/imgProc/Smoothing/smoothing.py blur
150+ @end_toggle
151+
152+ #### Gaussian Filter:
126153
154+ - It is performed by the function ** GaussianBlur()** :
155+ Here we use 4 arguments (more details, check the OpenCV reference):
127156 - * src* : Source image
128157 - * dst* : Destination image
129158 - * Size(w, h)* : The size of the kernel to be used (the neighbors to be considered). \f$w\f$ and
@@ -134,35 +163,65 @@ Explanation
134163 - \f$\sigma_ {y}\f$: The standard deviation in y. Writing \f$0\f$ implies that \f$\sigma_ {y}\f$ is
135164 calculated using kernel size.
136165
137- -# ** Median Filter:**
166+ @add_toggle_cpp
167+ @snippet cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp gaussianblur
168+ @end_toggle
138169
139- This filter is provided by the @ref cv::medianBlur function:
140- @snippet cpp/tutorial_code/ImgProc/Smoothing.cpp medianblur
170+ @add_toggle_java
171+ @snippet samples/java/tutorial_code/ImgProc/Smoothing/Smoothing.java gaussianblur
172+ @end_toggle
141173
142- We use three arguments:
174+ @add_toggle_python
175+ @snippet samples/python/tutorial_code/imgProc/Smoothing/smoothing.py gaussianblur
176+ @end_toggle
177+
178+ #### Median Filter:
143179
180+ - This filter is provided by the ** medianBlur()** function:
181+ We use three arguments:
144182 - * src* : Source image
145183 - * dst* : Destination image, must be the same type as * src*
146184 - * i* : Size of the kernel (only one because we use a square window). Must be odd.
147185
148- -# ** Bilateral Filter**
186+ @add_toggle_cpp
187+ @snippet cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp medianblur
188+ @end_toggle
149189
150- Provided by OpenCV function @ref cv::bilateralFilter
151- @snippet cpp/tutorial_code/ImgProc/Smoothing.cpp bilateralfilter
190+ @add_toggle_java
191+ @snippet samples/java/tutorial_code/ImgProc/Smoothing/Smoothing.java medianblur
192+ @end_toggle
152193
153- We use 5 arguments:
194+ @add_toggle_python
195+ @snippet samples/python/tutorial_code/imgProc/Smoothing/smoothing.py medianblur
196+ @end_toggle
197+
198+ #### Bilateral Filter
154199
200+ - Provided by OpenCV function ** bilateralFilter()**
201+ We use 5 arguments:
155202 - * src* : Source image
156203 - * dst* : Destination image
157204 - * d* : The diameter of each pixel neighborhood.
158205 - \f$\sigma_ {Color}\f$: Standard deviation in the color space.
159206 - \f$\sigma_ {Space}\f$: Standard deviation in the coordinate space (in pixel terms)
160207
208+ @add_toggle_cpp
209+ @snippet cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp bilateralfilter
210+ @end_toggle
211+
212+ @add_toggle_java
213+ @snippet samples/java/tutorial_code/ImgProc/Smoothing/Smoothing.java bilateralfilter
214+ @end_toggle
215+
216+ @add_toggle_python
217+ @snippet samples/python/tutorial_code/imgProc/Smoothing/smoothing.py bilateralfilter
218+ @end_toggle
219+
161220Results
162221-------
163222
164- - The code opens an image (in this case * lena.jpg* ) and display it under the effects of the 4
165- filters explained.
223+ - The code opens an image (in this case [ lena.jpg] ( https://raw.githubusercontent.com/opencv/opencv/master/samples/data/lena.jpg ) )
224+ and display it under the effects of the 4 filters explained.
166225- Here is a snapshot of the image smoothed using * medianBlur* :
167226
168227 ![ ] ( images/Smoothing_Tutorial_Result_Median_Filter.jpg )
0 commit comments