MATLAB exercise program (Laplace residual pyramid)

Source: Internet
Author: User

The Gaussian pyramid has been studied in the past, but today it seems wrong that the upper and lower layers of the pyramid should be the relationship of sampling, not the relationship of scaling, and Sigma on different layers should also be different.

The Laplace pyramid is applied in Image Fusion. The method is to first calculate the Laplace residual pyramid for the two images to be fused, and then use the template to combine each level of residual image to obtain the residual pyramid for the fusion image, then, the pyramid is reconstructed to obtain the final fusion image, and the details of each scale of the image are retained. (Note: During fusion, the template will generally be blurred with the Gaussian function)

However, here we do not implement fusion, but only implement the establishment of the Laplace pyramid.

The following figure shows the construction of the pyramid (from Digital Image Processing (version 2):

J-level input images can be restored through J-1-level approximate images and J-level residual images.

The approximate filter is the Laplace filter template.

The Insert filter is a new filter template that samples the Laplace filter template.

The Laplace filter template is as follows:

W = 1/256*[1 4 6 4 1;
4 16 24 14 4;
6 24 36 24 6;
4 16 24 16 4;
1 4 6 4 1];

Generated residual pyramid:

The first four images are residual, And the last image is a four-level approximation of the source image. The last image and the residual image can be used to reconstruct the source image.

The Matlab code is as follows:

Main. m

Clear all; close all; clc1_img1_double(imread('lena.jpg '); [m n] = size (IMG); W = 1/256*[1 4 6 4 1; % Laplace filter 4 16 24 14 4; 6 24 36 24 6; 4 16 24 16 4; 1 4 6 4 1]; imgn {1} = IMG; for I = % filtering, subsample imgn {I} = imfilter (imgn {I-1}, W, 'replicate'); imgn {I} = imgn {I} (1: 2: size (imgn {I}, 1)-: 2: size (imgn {I}, 2)-1); % I-1 level approximate end for I = 5: -% adjust image size imgn {I-1} = imgn {I-1} (* size (imgn {I}, 1), * size (imgn {I }, 2); End for I = % to get the residual image, level I prediction residual imgn {I }= imgn {I}-expand (imgn {I + 1}, W ); end for I = 4:-1:1% residual image reconstruction original image imgn {I} = imgn {I} + expand (imgn {I + 1}, W ); endimshow (uint8 (imgn {1 }));

Expand. m

Function Re = expand (IMG, W) IMG = double (IMG); W = W * 4; [m n] = size (IMG ); [m n] = size (w); % Insert filter w_up_left = W (1: 2: M, 1: 2: N); w_up_right = W (1: 2: m, 2: 2: N); w_down_left = W (2: 2: M, 1: 2: N); w_down_right = W (2: 2: m, 2: 2: n); img_up_left = imfilter (IMG, w_up_left, 'replace ', 'same'); img_up_right = imfilter (IMG, w_up_right, 'replicate', 'same '); img_down_left = imfilter (IMG, w_down_left, 'replace ', 'same'); img_down_right = imfilter (IMG, w_down_right, 'replicate', 'same '); re = zeros (M * 2, N * 2); % on sample Re (1: 2: M *: 2: N * 2) = img_up_left; Re (2: 2: M * 2, 1: 2: N * 2) = img_up_right; Re (1: 2: M * 2, 2: 2: N * 2) = img_down_left; Re (2: 2: M * 2, 2: 2: N * 2) = img_down_right; End

 

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.