Principle, difference and OPENCV realization of sampling and down-sampling on pyramid

Source: Internet
Author: User
Image Pyramid

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

The most commonly used method of generating image pyramids is to smooth the image with Gaussian function, reduce the resolution to half of the original one at a time, resulting in an image sequence {ml,ml-1,......,m0}, the image pyramid storage capacity of n^2* (1+1/4+1/16+ ...) = (4*n^2)/3.

As shown above: The rightmost image is the original, right-to-left, followed by Gaussian smoothing 1, 2, and 3 times after the images, which together form the image pyramid.

Image pyramid This structure has a wide range of uses in image processing. The most famous feature matching operator sift is done by constructing the image pyramid. The application of image pyramid in the SIFT feature extraction algorithm can be found in Rachel Zhang's blog "Sift Feature extraction analysis". Program Analysis

/* * FileName:pyramids.cpp * author:xiahouzuoxin @163.com * version:v1.0 * Date:sat SEP 2014 07:04:2 
9 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 Co
        ut<< "error:input image ' 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:/* 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; }

    }
}

The functions of descending sampling and interpolation using Gaussian image pyramid are Pyrdown and Pyrup respectively, the parameters are original image, sampled result image and image size after sampling.

The reduced-sampling operation in the above procedure is based on a multiple of 2, so it is required that the length of the input image must be 2^n. if (Src.cols & (Src.cols-1)) is the statement used to determine if the original image's column is 2^n. Please carefully understand this method of judging whether a number is 2^n--x* (x-1) returns 0 means X is 2^n, otherwise it is not. results show

The following series of images show that the original image is first reduced by the image pyramid (there will be data loss), and then the image process is restored by pyramid interpolation. Because of the loss of data during the process of descending sampling, it is possible to see that the image restored to the original image is blurred than the original image.

Picture-and-note original image

Fig. 1 Images after descending sampling

Fig. 2 Images after descending sampling

After 2 drop sampling, the image after 1 image pyramid interpolation operation is the same size as the image after 1 drops, but becomes blurred

After 2 drop sampling, the image after 2 image pyramid interpolation operation is the same size as the original, but becomes blurred

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.