일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 빅 데이타
- data science
- 김양재 목사
- 김양재 목사님
- 빅데이터
- node.js
- c++
- 빅 데이터
- Artificial Intelligence
- Big Data
- 통계
- 김양재
- 확률
- 인공지능
- Machine Learning
- Statistics
- WebGL
- MongoDB
- 딥러닝
- 우리들교회
- 데이터 과학
- 몽고디비
- 주일설교
- nodeJS
- Deep learning
- R
- 빅데이타
- probability
- No SQL
- openCV
Archives
- Today
- Total
Scientific Computing & Data Science
[OpenCV] Image Filtering 본문
[Theory]
where
f(i+k, j+l) : source image
h(k, l) : kernel
g(i, j) : filtered image
[File Types]
- Box Filter
- Gaussian Filter
- Median Filter
- Bilateral Filter : refer to this link
[Source Code]
#include "stdafx.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace std;
using namespace cv;
// Global Variables
int DELAY_CAPTION = 1500;
int DELAY_BLUR = 100;
int MAX_KERNEL_LENGTH = 31;
Mat src; Mat dst;
char window_name[] = "Filter Demo 1";
/// Function headers
int display_caption( char* caption );
int display_dst( int delay );
//////////////////////////////////////////////////////////////////
// function : main
int _tmain(int argc, _TCHAR* argv[])
{
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
/// Load the source image
src = imread( [YOUR_IMAGE_PATH], 1 );
if( ( src.rows == 0 ) && ( src.cols == 0 ) ) {
return 0;
}
if( display_caption( "Original Image" ) != 0 ) {
return 0;
}
dst = src.clone();
if( display_dst( DELAY_CAPTION ) != 0 ) {
return 0;
}
/// Applying Homogeneous blur
if( display_caption( "Homogeneous Blur" ) != 0 ) {
return 0;
}
for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) {
blur( src, dst, Size( i, i ), Point( -1, -1 ) );
if( display_dst( DELAY_BLUR ) != 0 ) {
return 0;
}
}
/// Applying Gaussian blur
if( display_caption( "Gaussian Blur" ) != 0 ) {
return 0;
}
for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) {
GaussianBlur( src, dst, Size( i, i ), 0, 0 );
if( display_dst( DELAY_BLUR ) != 0 ) {
return 0;
}
}
/// Applying Median blur
if( display_caption( "Median Blur" ) != 0 ) {
return 0;
}
for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) {
medianBlur ( src, dst, i );
if( display_dst( DELAY_BLUR ) != 0 ) {
return 0;
}
}
/// Applying Bilateral Filter
if( display_caption( "Bilateral Blur" ) != 0 ) {
return 0;
}
for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) {
bilateralFilter ( src, dst, i, i*2, i/2 );
if( display_dst( DELAY_BLUR ) != 0 ) {
return 0;
}
}
/// Wait until user press a key
display_caption( "End: Press a key!" );
waitKey(0);
return 0;
}
//////////////////////////////////////////////////////////////////
// function : display_caption
int display_caption( char* caption )
{
dst = Mat::zeros( src.size(), src.type() );
putText( dst, caption, Point( src.cols/4, src.rows/2), CV_FONT_HERSHEY_COMPLEX, 1, Scalar(255, 255, 255) );
imshow( window_name, dst );
int c = waitKey( DELAY_CAPTION );
if( c >= 0 ) {
return -1;
}
return 0;
}
//////////////////////////////////////////////////////////////////
// function : display_dst
int display_dst( int delay )
{
imshow( window_name, dst );
int c = waitKey ( delay );
if( c >= 0 ) {
return -1;
}
return 0;
}
[Normalized Block Filter]
for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) {
blur( src, dst, Size( i, i ), Point( -1, -1 ) );
if( display_dst( DELAY_BLUR ) != 0 ) {
return 0;
}
}
- src : Source image.
- dst : Destination image.
- Size(w, h) : Size of the kernel to be used.
- Point(-1, -1) : anchor point location. Negative value denotes the center of the kernel is considered.
[Gaussian Filter]
for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) {
GaussianBlur( src, dst, Size( i, i ), 0, 0 );
if( display_dst( DELAY_BLUR ) != 0 ) {
return 0;
}
}
- src : Source image.
- dst : Destination image.
- Size(w, h) : Size of the kernel to be used.
- : Standard deviation in x. 0 implies uses kernel size.
- : Standard deviation in x. 0 implies uses kernel size.
[Median Filter]
for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) {
medianBlur ( src, dst, i );
if( display_dst( DELAY_BLUR ) != 0 ) {
return 0;
}
}
- src : Source image.
- dst : Destination image.
- i : Size of the kernel.
[Bilateral Filter]
for ( int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2 ) {
bilateralFilter ( src, dst, i, i*2, i/2 );
if( display_dst( DELAY_BLUR ) != 0 ) {
return 0;
}
}
- src : Source image.
- dst : Destination image.
- d : The diameter of each pixel neighborhood.
- : Standard deviation in color space.
- : Standard deviation in the coordinate space.
'Programming > OpenCV' 카테고리의 다른 글
[OpenCV] Camera Frame Capture (0) | 2015.03.31 |
---|---|
[OpenCV] Image Pyramid (0) | 2015.03.24 |
[OpenCV] putText 함수를 이용한 Text 출력 (0) | 2015.03.17 |
[OpenCV] 이미지 Contrast & Brightness 조정하기 (0) | 2015.03.17 |
[OpenCV] Low-level Pointer를 사용하여 특정 Pixel에 접근하기 (0) | 2015.03.05 |
Comments