You are on page 1of 12

Lections on Image analysis, OpenCV

5. Smoothing

www.uralvision.blogspot.com perevalovds@gmail.com
USU / IMM Fall 2010
Smoothing
The most frequently used function for smoothing is
void GaussianBlur(Const Mat & src //Input image
Mat & dst //Output image
Size ksize //Size of the smoothing window
double sigmaX //Parameters of the Gaussian
double sigmaY= 0
int borderType= BORDER_DEFAULT) //how to work with
//boundaries

- The function performs smoothing src using a Gaussian function.


-dst will have the same type and size as src.
- Is allowed to dst == src.
-ksize - The size of the filter kernel, where the dimensions must be odd.
-sigmaX,sigmaY - Standard deviation of X and Y. If 0, calculated from
ksize.
-borderType - How to work at the border For example, BORDER_REFLECT.
Smoothing
Example
Mat image = imread ("3dart.jpg");
Mat blurred1, blurred2;
GaussianBlur (image, blurred1, cv::Size (11, 11), 0);
GaussianBlur (image, blurred2, cv::Size (41, 41), 0);

image blurred1 blurred2

http://www.innocentenglish.com/funny-pics/best-pics/stairs-sidewalk-art.jpg
Smoothing
Other functions that perform smoothing:
medianBlur - Median filtering
blur - Smoothing of the square window (averaging)
filter2D - Smoothing with any filter, represented as a matrix

GaussianBlur medianBlur blur

All three methods worked with a filter size of 11x11 pixels.


Gaussian filter gave the most natural result.
Median - identified areas of the same color and remove small parts.
Averaging filter - see unwanted artifacts - square edges of objects.
Why smoothing is applied
1. Removal of small noise on the image for subsequent image
analysis.
Done by using a filter of small size.

More often - using a Gaussian filter, at least - the median


filtering.
Why smoothing is applied
2. Elimination of the inhomogeneity of the background.
Apply a Gaussian filter of large size, and subtracted from the
original image is smoothed image.

Original image Difference between the


Smoothing filter size of 201x201
with uniform background pixels original and smoothed
images.
The background is now
uniformly black.
In the example, use pictures, obtained by inverting
http://www.eyesontutorials.com/images/Designing/Jeka/tut180_dark_wallpaper/12.jpg
Why smoothing is applied
3. Underline the subjects in pixels.
(The fact of the theory: the difference of two Gaussians
approximates the Laplacian).
Using two Gaussian filter with size a and ~2a.

Original image The difference between two smoothed images


with a radius of 3 and 7, multiplied by 20.
Bright color marks the edges of objects.
Why smoothing is applied
4. Not related to computer vision
and to computer graphics:

- Gaussian filter simulated the effect of defocusing.

- Asymmetric filter creates the effect of "blurring speed" (motion blur).

Lateral motion Progress Rotation


Practical task 2
Make a cartoon, in which
original image is subjected to an increasing blurring of window size. That is gradually
eroded.

1. As a picture that should wash out - to select the image object whose name begins with
the first letter of your last name.

2. To use the blur algorithm


Gaussian filter (if your name is of even length),
or a median filter (if your name is odd length).

3. The cartoon must be at least 100 frames.

4. Result - send a link to your video on youtube, and cpp-code.


Practical task 2
Clarification of how to do

In OpenCV can explicitly create avi files.


We offer an easier way.

1. Images stored on the disc in one folder in the format. Bmp, with names
image000.bmp, image001.bmp, ....

2. Then of them do avi-file using the VirtualDub


(File-> Open video file, and in the dialog box to specify the first picture from the set.
Thereafter Video -> Compresson, choose a codec.
Finally, File -> Save as avi ... - Record avi-file).

3. Publish the video on youtube.


Practical Task 3
Using
1) excision of the image,
(See 2 nd lecture, "5. Working with rectangular subdomains image)
2) function to resize resize ()
3) summation of images with the weights
(See 2 nd lecture, "3. Linear operations on images)

realize the effect of "Progress.

The result represented as a cpp-file as well as the input and output images.
Name of the object on the input image must begin with the first letter of your last name.
Practical Task 3
Clarification of how to do

Cut N = 20 rectangular areas - image [i], they increase in size,


and from them we construct the sum

1.0 / N * image [0] + 1.0 / N * image [1] + ... + 1.0 / N * image [N-1];

this will be the result.

You might also like