"Study OpenCV" Chinese version 5th Chapter 1th question
Outline
Topic Requirements |
A program code |
B Program code |
C Program code |
Result picture |
Title Requirements:
Note: The requirements in the book are expanded and adjusted
Loads an image with an interesting texture.
A. Use the Cvsmooth function to smooth the image in a variety of ways
b, using a symmetrical smoothing window with a size of 3x3, 5x5, 9x9, and 11x11, showing the result
C, smoothing the image with a 5x5 Gaussian filter two times and smoothing the output with two 11x11 smoothing is close to the same? Why?
D. Compare the effects of different smoothing methods and consult the data to find out the different processing effects and their respective advantages.
a program code:
1 //OpenCVExerciseTesting.cpp: Defines the entry point of the console application. 2 //3 //d:\\work\\work_programming\\source\\image\\lena.jpg4 5 6#include"stdafx.h"7#include <cv.h>8#include 9#include <iostream>Ten using namespaceCV; One using namespacestd; A //function declaration---->-->--->-->--->-->--->// - - the - //<--<--<--<--<--<--<--<--<--Function Declaration// - - int_tmain (intARGC, _tchar*argv[]) + { - Const Char* FileName ="d:\\work\\work_programming\\source\\image\\ texture \ \ Texture _ grayscale. jpg"; + AIplimage * img =cvloadimage (FileName, cv_load_image_unchanged); at assert (IMG); - -Iplimage * DST =cvcloneimage (IMG); - //Dst->origin = img->origin; - Cvzero (DST); - inCvnamedwindow ("Exercisewindow",0); -Cvnamedwindow ("simple Blur",0); toCvnamedwindow ("Simple no scaling blur",0); +Cvnamedwindow ("Median filter blur",0); -Cvnamedwindow ("Gaussian Blur",0); theCvnamedwindow ("Bilateral filtering",0); * $Cvshowimage ("Exercisewindow", IMG);Panax Notoginseng - //---------------------------simple blur: Start--------------------------------// the +Cvsmooth (IMG, DST, Cv_blur,5); A the /*int i = 0; + While (i<5) - { $ Cvsmooth (DST, DST, Cv_blur, 5); $ i++; - }*/ -Cvshowimage ("simple Blur", DST); the - Wuyi //---------------------------simple blur: End--------------------------------// the - //---------------------------Simple no-zoom blur: Start--------------------------------// Wu - //Note: Using the Cv_blur_no_scale smoothing type, the input image and the output image must have different data precision AboutIplimage * Blur_no_scale = Cvcreateimage (Cvsize (Img->width, Img->height), ipl_depth_16s, img->nchannels); $Blur_no_scale->origin = img->origin; - Cvzero (Blur_no_scale); - -Cvsmooth (IMG, Blur_no_scale, Cv_blur_no_scale,5); A +Cvshowimage ("Simple no scaling blur", Blur_no_scale); the - //---------------------------Simple no-zoom blur: End--------------------------------// $ the //---------------------------Median filter: Start--------------------------------// the the //Note: The Cv_median smoothing type does not support in-place mode theIplimage * Image_median =cvcloneimage (IMG); - Cvzero (Image_median); in theCvsmooth (IMG, Image_median, Cv_median,5); the AboutCvshowimage ("Median filter blur", Image_median); the the //---------------------------Median filter: End--------------------------------// the + //---------------------------Gaussian Blur: Start--------------------------------// - theIplimage * Image_gauss =cvcloneimage (IMG);Bayi Cvzero (Image_gauss); the theCvsmooth (IMG, Image_gauss, Cv_gaussian,5,5,3,3); - -Cvshowimage ("Gaussian Blur", Image_gauss); the the //---------------------------Gaussian Blur: End--------------------------------// the the //---------------------------Bilateral filtering: Start--------------------------------// - the //Special Note: The input and output images of the Cv_bilateral smoothing type must be 8u, which is the grayscale image the //because the smoothing type does not support in-place mode, it is important to increase the temporary image when smoothing multiple times. the 94 /*iplimage * Img_gray = Cvcreateimage (Cvgetsize (IMG), ipl_depth_8u, 1); the iplimage * Image_bil = Cvcreateimage (Cvgetsize (IMG), ipl_depth_8u, 1); the Cvcvtcolor (IMG, Img_gray, cv_bgr2gray);*/ theIplimage * Image_bil =cvcloneimage (IMG);98 AboutIplimage * Temp_image =cvcloneimage (IMG); - Cvzero (temp_image);101 102Cvsmooth (IMG, temp_image, Cv_bilateral,3,3, One, One);103 104 intj =0; the while(j< -)106 {107 //Note: The last two in the Cvsmooth parameter when using the Cv_bilateral smoothing type108Cvsmooth (Temp_image, Image_bil, Cv_bilateral,7,7, One, One);109 //Cvsmooth (Temp_image, Image_bil, Cv_bilateral, 3, 3); the 111 cvcopyimage (Image_bil, temp_image); theJ + +;113 } the the //Cvsmooth (IMG, Image_bil, cv_bilateral, 3, 3,11,11); the 117Cvshowimage ("Bilateral filtering", Image_bil);118 119 //---------------------------Bilateral filtering: End--------------------------------// - 121Cvwaitkey (0);122 123Cvreleaseimage (&img);124Cvreleaseimage (&DST); theCvreleaseimage (&Blur_no_scale);126Cvreleaseimage (&Image_median);127Cvreleaseimage (&Image_gauss); -Cvreleaseimage (&Image_bil);129 theCvdestroywindow ("Exercisewindow"); 131Cvdestroywindow ("simple Blur"); theCvdestroywindow ("Simple no scaling blur");133Cvdestroywindow ("Median filter blur");134Cvdestroywindow ("Gaussian Blur");135Cvdestroywindow ("Bilateral filtering");136 137 return 0;138 }139
Next:
Preserving the processing image of the bilateral filter
Exercise 5.1 uses Cvsmooth to test the effects of different smoothing methods and the effect of different smoothing windows on processing effects