Opencv Image Processing-sampling pyramid

Source: Internet
Author: User

Reprinted please indicate the source: http://xiahouzuoxin.github.io/notes

Image pyramid

The image pyramid is a collection of images with different resolutions generated by smoothing and downsampling the original image. The pyramid structure (pyramid) is an image storage data structure suitable for multi-resolution processing.

The most common method to generate the image pyramid is to use Gaussian function to smooth the image, each time the resolution is reduced to half of the original, thus obtaining an image sequence {ml, ML-1 ,......, M0}, the storage of the image pyramid isN^2*(1+1/4+1/16+...)=(4*N^2)/3.

For example, the rightmost is the original image, and the right-to-left is the image after Gaussian smoothing for one, two, and three times. These images constitute the image pyramid.

Image pyramid structure is widely used in image processing. The most famous feature matching operator sift is done by constructing an image pyramid. For the application of image pyramid in the sift feature extraction algorithm, see Rachel Zhang's blog "sift Feature Extraction analysis ".

Program Analysis
/* * FileName : pyramids.cpp * Author   : xiahouzuoxin @163.com * Version  : v1.0 * Date     : Sat 20 Sep 2014 07:04:29 PM CST * Brief    :  *  * Copyright (C) MICL,USTB */#include <iostream>#include "cv.h" #include "highgui.h"#include "opencv2/imgproc/imgproc.hpp"using namespace std;using namespace cv;const char *wn = "Pyramids Demo";int main(int argc, char *argv[]){    if (argc < 2) {        cout<<"Usage: ./pyramids [file name]"<<endl;        return -1;    }    Mat src = imread(argv[1]);    if (!src.data) {        cout<<"Error: read image error."<<endl;        return -1;    }    /* Size of input image must be 2^n */    if ( src.cols & (src.cols-1) ) {  // src.cols > 0 first        cout<<"Error: input image‘s column must be 2^n"<<endl;        return -1;    }    if ( src.rows & (src.rows-1) ) {  // src.cols > 0 first        cout<<"Error: input image‘s row must be 2^n"<<endl;        return -1;    }    cout<<"User Guide:"<<endl;    cout<<"---------------------"<<endl;    cout<<"u   -> Zoom out"<<endl;    cout<<"d   -> Zoom in"<<endl;    cout<<"ESC -> Exit program"<<endl;    namedWindow(wn, WINDOW_AUTOSIZE);    imshow(wn, src);    Mat cur = src;    Mat dst = cur;    int end_while = 0;    while(!end_while) {        char c;        c = waitKey(10);        switch (c) {        case 27:   /* ESC */            end_while = 1;            break;        case ‘u‘:            pyrUp(cur, dst, Size(cur.cols*2, cur.rows*2));            imshow(wn, dst);            cur = dst;            break;        case ‘d‘:            pyrDown(cur, dst, Size(cur.cols/2, cur.rows/2));            imshow(wn, dst);            cur = dst;            break;        default:            break;        }    }}
  1. The downsample and interpolation functions using the Gaussian image pyramid are:pyrDownAndpyrUpThe parameters are the original image, the sample result image, and the size of the sampled image in sequence.

  2. The downsampling operation in the preceding procedure is performed in multiples of 2. Therefore, the length and width of the input image must be 2 ^ n.if ( src.cols & (src.cols-1) )Is a statement used to determine whether the column of the original image is 2 ^ n. Please carefully evaluate this method to determine whether a number is 2 ^ n -- x * (x-1) returns 0 to indicate that X is 2 ^ N, otherwise not.

Result Display

The following series of images first show the original image through the image pyramid downsampling (there will be data loss), and then restore the image change process in the image process through pyramid interpolation. Due to data loss during the downsampling process, we can see that the image restored to the original image size is more blurred than the original image.

Source image

Figure 1 downsample Image

Figure 2 downsample Images

After two downsample operations, the image after one pyramid interpolation operation is the same size as the image after one downsample operation, but it becomes blurred.

After two downsampling operations and two pyramid interpolation operations, the image is of the same size as the original image, but blurred.

Opencv Image Processing-sampling pyramid

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.