MATLAB Practice Program (Image Haar wavelet transform)

Source: Internet
Author: User

About wavelet transform I just have a very plain understanding. However, the wavelet transform can be combined with Fourier transform to understand.

The Fourier transform is to decompose the original function with a series of cosine functions of different frequencies, and the coefficients of the original function at different frequencies of the sine cosine are obtained after transformation.

Wavelet transform uses a series of different scale wavelet to decompose the original function, and the coefficients of the original function under different scale wavelets are obtained.

Different wavelets are decomposed by translation and scale transformation, which is to get the time characteristic of the original function, and the scale transformation is to get the frequency characteristic of the original function.

Wavelet Transform steps:

1. Compare the starting part of the wavelet W (t) and the original function f (t) to calculate the coefficient c. The coefficient c indicates how similar the part function is to the wavelet.

2. Move the wavelet to the right to the K unit, get the wavelet w (t-k), repeat 1. Repeat the department until the function f ends.

3. Expand the wavelet w (t), get the wavelet w (T/2), repeat steps.

4. Continue to expand the wavelet, repeat the double.

The Haar wavelet that I use here, the scaling function is [1 1], and the wavelets function is [1-1]. Is the simplest of the little waves.

First look at the effect of decomposition, this time I chose a large image:

Full decomposition wavelet packet with scale 2:

Here is the MATLAB code:

Main.m

Clear all;
Close all;
CLC;

Img=double (Imread (' Lena (2). jpg '));
[M N]=size (IMG);

[LL LH HL hh]=haar_dwt2d (IMG);  % of course dwt2 (IMG, ' Haar ') is the same, I just want to understand the details
img=[ll LH; HL HH];      % one layer decomposition

imgn=zeros (m,n);
For I=0:M/2:M/2 for
    j=0:n/2:n/2
        [LL LH HL hh]=haar_dwt2d (img (I+1:I+M/2,J+1:J+N/2));% decomposition of four images after a layer is decomposed separately
        IMGN (I+1:I+M/2,J+1:J+N/2) =[ll LH; HL HH];  
    End
End

Imshow (IMGN)

Haar_dwt2d.m

function [LL LH HL hh]=haar_dwt2d (img)
    [M N]=size (IMG);
    For i=1:m       % per line decomposition
        [L h]=haar_dwt (IMG (i,:));
        IMG (i,:) =[l H];
    End
    for j=1:n       % each column is decomposed
       [L h]=haar_dwt (IMG (:, j));
       IMG (:, j) =[l H];
    End
    of the original decomposition should not be added Mat2gray, but in order to have a good display effect on the addition of
    Ll=mat2gray (IMG (1:M/2,1:N/2));          % of the ranks are low frequency  
    Lh=mat2gray (img (1:m/2,n/2+1:n));        % line Low Frequency column HF
    Hl=mat2gray (IMG (M/2+1:M,1:N/2));        % line high frequency column low frequency
    hh=mat2gray (img (m/2+1:m,n/2+1:n));      % of the ranks are high-frequency
    
end

Haar_dwt.m

function [L h]=haar_dwt (f)% Obviously, I did not do border processing, the picture is preferably 2^n*2^n type of
    n=length (f);
    N=N/2;
    L=zeros (1,n);   % Low Frequency component
    H=zeros (1,n);   % high frequency component for
    i=1:n
        L (i) = (f (2*i-1) +f (2*i))/sqrt (2);
        H (i) = (f (2*i-1)-F (2*i))/sqrt (2);
    End
    
End

Reference:

Http://amath.colorado.edu/courses/5720/2000Spr/Labs/Haar/haar.html

http://www.cs.ucf.edu/~mali/haar/

Http://wenku.baidu.com/view/7839b821aaea998fcc220eed.html

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.