-
Notifications
You must be signed in to change notification settings - Fork 10
/
filter_demo.cpp
72 lines (56 loc) · 1.76 KB
/
filter_demo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*------------------------------------------------------/
* Image Proccessing with Deep Learning
* OpenCV : Filter Demo
* Created: 2021-Spring
------------------------------------------------------*/
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
void main()
{
cv::Mat src, dst;
src = cv::imread("sudoku.jpg", 0);
int i = 3;
Size kernelSize = cv::Size(i, i);
/* Blur */
cv::blur(src, dst, cv::Size(i, i), cv::Point(-1, -1));
namedWindow("Blur", WINDOW_NORMAL);
imshow("Blur", dst);
/* Gaussian Filter */
cv::GaussianBlur(src, dst, cv::Size(i, i), 0, 0);
namedWindow("Gaussian", WINDOW_NORMAL);
imshow("Gaussian", dst);
/* Median Filter */
cv::medianBlur(src, dst, i);
namedWindow("Median", CV_WINDOW_AUTOSIZE);
imshow("Median", dst);
/* Bilateral filter */
cv::bilateralFilter(src, dst, i, i * 2, i / 2);
namedWindow("Bilateral", CV_WINDOW_AUTOSIZE);
imshow("Bilateral", dst);
/* Laplacian Filter */
int kernel_size = 3;
int scale = 1;
int delta = 0;
int ddepth = CV_16S;
cv::Laplacian(src, dst, ddepth, kernel_size, scale, delta, cv::BORDER_DEFAULT);
src.convertTo(src, CV_16S);
cv::Mat result_laplcaian = src - dst;
result_laplcaian.convertTo(result_laplcaian, CV_8U);
namedWindow("Laplacian", CV_WINDOW_AUTOSIZE);
cv::imshow("Laplacian", result_laplcaian);
/* 2D Convolution of a filter kernel */
/* Design a normalized box filter kernel 5 by 5 */
src.convertTo(src, CV_8UC1);
Mat kernel;
delta = 0;
ddepth = -1;
kernel_size = 5;
Point anchor = Point(-1, -1);
kernel = Mat::ones(kernel_size, kernel_size, CV_32F) / (float)(kernel_size * kernel_size);
filter2D(src, dst, ddepth, kernel, anchor, delta);
namedWindow("Conv2D", CV_WINDOW_AUTOSIZE);
cv::imshow("Conv2D", dst);
cv::waitKey(0);
}