opencv lections: 5. smoothing

12

Click here to load reader

Upload: denis-perevalov

Post on 04-Apr-2015

7.359 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: OpenCV Lections: 5. Smoothing

Lections on Image analysis, OpenCV

5. Smoothing

USU / IMM Fall 2010www.uralvision.blogspot.com [email protected]

Page 2: OpenCV Lections: 5. Smoothing

SmoothingThe most frequently used function for smoothing isvoid GaussianBlur(Const Mat & src //Input image

Mat & dst //Output imageSize ksize //Size of the smoothing windowdouble sigmaX //Parameters of the Gaussiandouble 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 fromksize.-borderType - How to work at the border For example, BORDER_REFLECT.

Page 3: OpenCV Lections: 5. Smoothing

SmoothingExampleMat image = imread ("3dart.jpg");Mat blurred1, blurred2;GaussianBlur (image, blurred1, cv::Size (11, 11), 0);GaussianBlur (image, blurred2, cv::Size (41, 41), 0);

imageblurred1 blurred2

http://www.innocentenglish.com/funny-pics/best-pics/stairs-sidewalk-art.jpg

Page 4: OpenCV Lections: 5. Smoothing

SmoothingOther functions that perform smoothing:medianBlur - Median filteringblur - 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.

Page 5: OpenCV Lections: 5. Smoothing

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.

Page 6: OpenCV Lections: 5. Smoothing

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.

In the example, use pictures, obtained by inverting http://www.eyesontutorials.com/images/Designing/Jeka/tut180_dark_wallpaper/12.jpg

Original imagewith uniform background

Smoothing filter size of 201x201 pixels

Difference between the original and smoothed images.The background is now uniformly black.

Page 7: OpenCV Lections: 5. Smoothing

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.

Page 8: OpenCV Lections: 5. Smoothing

Why smoothing is applied

4. Not related to computer visionand to computer graphics:

- Gaussian filter simulated the effect of defocusing.

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

Lateral motion Progress Rotation

Page 9: OpenCV Lections: 5. Smoothing

Practical task 2Make a cartoon, in whichoriginal 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 algorithmGaussian 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.

Page 10: OpenCV Lections: 5. Smoothing

Practical task 2Clarification 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 namesimage000.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.

Page 11: OpenCV Lections: 5. Smoothing

Practical Task 3Using1) 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.

Page 12: OpenCV Lections: 5. Smoothing

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.