1
1
Smoothing Images {#tutorial_gausian_median_blur_bilateral_filter}
2
2
================
3
3
4
+ @next_tutorial{tutorial_erosion_dilatation}
5
+
4
6
Goal
5
7
----
6
8
7
9
In this tutorial you will learn how to apply diverse linear filters to smooth images using OpenCV
8
10
functions such as:
9
11
10
- - @ ref cv:: blur
11
- - @ ref cv:: GaussianBlur
12
- - @ ref cv:: medianBlur
13
- - @ ref cv:: bilateralFilter
12
+ - ** blur() **
13
+ - ** GaussianBlur() **
14
+ - ** medianBlur() **
15
+ - ** bilateralFilter() **
14
16
15
17
Theory
16
18
------
92
94
- Loads an image
93
95
- Applies 4 different kinds of filters (explained in Theory) and show the filtered images
94
96
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
95
107
- ** 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
+
97
118
- ** 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
99
121
100
122
Explanation
101
123
-----------
102
124
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.
106
127
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:
109
129
130
+ - OpenCV offers the function ** blur()** to perform smoothing with this filter.
110
131
We specify 4 arguments (more details, check the Reference):
111
-
112
132
- * src* : Source image
113
133
- * 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
115
135
* h* pixels)
116
136
- * Point(-1, -1)* : Indicates where the anchor point (the pixel evaluated) is located with
117
137
respect to the neighborhood. If there is a negative value, then the center of the kernel is
118
138
considered the anchor point.
119
139
120
- -# ** Gaussian Filter:**
140
+ @add_toggle_cpp
141
+ @snippet cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp blur
142
+ @end_toggle
121
143
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
124
147
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:
126
153
154
+ - It is performed by the function ** GaussianBlur()** :
155
+ Here we use 4 arguments (more details, check the OpenCV reference):
127
156
- * src* : Source image
128
157
- * dst* : Destination image
129
158
- * 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
134
163
- \f$\sigma_ {y}\f$: The standard deviation in y. Writing \f$0\f$ implies that \f$\sigma_ {y}\f$ is
135
164
calculated using kernel size.
136
165
137
- -# ** Median Filter:**
166
+ @add_toggle_cpp
167
+ @snippet cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp gaussianblur
168
+ @end_toggle
138
169
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
141
173
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:
143
179
180
+ - This filter is provided by the ** medianBlur()** function:
181
+ We use three arguments:
144
182
- * src* : Source image
145
183
- * dst* : Destination image, must be the same type as * src*
146
184
- * i* : Size of the kernel (only one because we use a square window). Must be odd.
147
185
148
- -# ** Bilateral Filter**
186
+ @add_toggle_cpp
187
+ @snippet cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp medianblur
188
+ @end_toggle
149
189
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
152
193
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
154
199
200
+ - Provided by OpenCV function ** bilateralFilter()**
201
+ We use 5 arguments:
155
202
- * src* : Source image
156
203
- * dst* : Destination image
157
204
- * d* : The diameter of each pixel neighborhood.
158
205
- \f$\sigma_ {Color}\f$: Standard deviation in the color space.
159
206
- \f$\sigma_ {Space}\f$: Standard deviation in the coordinate space (in pixel terms)
160
207
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
+
161
220
Results
162
221
-------
163
222
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.
166
225
- Here is a snapshot of the image smoothed using * medianBlur* :
167
226
168
227
![ ] ( images/Smoothing_Tutorial_Result_Median_Filter.jpg )
0 commit comments