04-27 07:56
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

[OpenCV] Image Pyramid 본문

Programming/OpenCV

[OpenCV] Image Pyramid

cinema4dr12 2015. 3. 24. 01:09

Theory

Image Pyramid

  • Image Pyramid란, 원본 이미지로부터 원하는 만큼 연속적으로 다운샘플링(downsample)을 하는 것을 의미합니다.
  •  Image Pyramid의 종류
      • Gaussian Pyramid : 이미지 다운샘플(downsample)
      • Laplacian Pyramid : 이미지 업샘플(upsample)
  • Gaussian Pyramid
      • i 번째 레이어를 \(G_i\), (i + 1)번째 레이어를 \(G_{i+1}\)라고 하겠습니다.
      • (i + 1)번째 레이어를  얻으려면 다음의 Gaussian 커널을 \(G_i\)를 컨벌루션합니다:

        \( \displaystyle{\frac{1}{16}} \begin{bmatrix} 1 & 4 & 6 & 4 & 1 \\ 4 & 16 & 24 & 16 & 4 \\ 6 & 24 & 36 & 24 & 6 \\ 4  & 16 & 24 & 16 & 4 \\ 1 & 4 & 6 & 4 & 1 \end{bmatrix} \)

      • 모든 짝수 행과 짝수 열을 제거합니다.

Example Code

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
#include "stdafx.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
 
using namespace cv;
 
/// Global variables
cv::Mat src, dst, tmp;
char* window_name = "Pyramids Demo";
 
//////////////////////////////////////////////////////////////////
// function : main
int main( int argc, char** argv )
{
    /// General instructions
    printf"\n Zoom In-Out demo \n " );
    printf"------------------ \n" );
    printf" * [u] -> Zoom in \n" );
    printf" * [d] -> Zoom out \n" );
    printf" * [ESC] -> Close program \n \n" );
 
    /// Test image - Make sure it s divisible by 2^{n}
    src = imread( [YOUR_IMAGE_PATH] );
 
    if!src.data ) {
        printf(" No data! -- Exiting the program \n");
        return -1;
    }
 
    tmp = src;
    dst = tmp;
 
    /// Create window
    namedWindow( window_name, CV_WINDOW_AUTOSIZE );
    imshow( window_name, dst );
 
    /// Loop
    whiletrue ) {
        int c;
        c = waitKey(10);
 
        if( (char)c == 27 ) {
            break;
        }
 
        if( (char)c == 'u' ) {
            pyrUp( tmp, dst, Size( tmp.cols*2, tmp.rows*2 ) );
            printf"** Zoom In: Image x 2 \n" );
        }
        else if( (char)c == 'd' ) {
            pyrDown( tmp, dst, Size( tmp.cols/2, tmp.rows/2 ) );
            printf"** Zoom Out: Image / 2 \n" );
        }
 
        imshow( window_name, dst );
        tmp = dst;
    }
 
    return 0;
}
cs


Comments