Morlet Wavelet

This is a simple Morlet Wavelet (Gabor wavelet) generator, which can be used for edge detecting.

CODE

% 2d morlet kernel generator
% input:
%       hori:   horizontal grid point amount
%       vert:   vertical grid point amount
%       theta:  theta
%       sigma:  controls the size of the kernel
%       npeaks: number of significant peaks appearing in the kernel     
% output:
%       psi: a 2d Morlet wavelet kernel (psi is complex)
%
function [psi] = morlet_2d(hori, vert, theta, sigma, npeaks)

    xi = 1 / npeaks * 4 * sigma;
    % 3 * sigma for each side
    %width = 6 * sigma;
    width = 18;
    height = width;
    x = linspace(- width / 2, width / 2, hori);
    y = linspace(- height / 2, height / 2, vert);
    [X, Y] = meshgrid(x, y);
    
    ue0 = X * cos(theta) + Y * sin(theta);
    u2 = X .^ 2 + Y .^ 2;
    k1 = exp(1i * 2 * pi / xi * ue0);
    k2 = exp(-0.5 * u2 / (sigma ^ 2));
    
    % get C2 (zero mean)
    C2 = sum(sum(k1 .* k2)) ./ sum(k2(:)); 
    % get C1 (one norm)
    tmp = (k1 - C2) .* k2;
    product = tmp .* conj(tmp);
    C1 = 1 ./ sum(product(:)) ^ 0.5;
    % result
    psi = C1 * (k1 - C2) .* k2;
end

TEST RESULT

I used both of the following images for testing.

butterfly   noise.circle

I used different sigma values and different theta values.

sigma = [1 3 6];
theta = [0 pi/6 pi/4 pi/3 pi/2 2*pi/3 3*pi/4 5*pi/6];

Here are the Morlet wavelet kernels I got:

Real part:

kernel_real

Imag part:

kernel_imag

For the Butterfly image, here are the convolution results.

With real kernels:

butter_real

With imag kernels:

butter_imag

For the noised_circle image, here are the convolution results.

With real kernels:

circle_real

With imag kernels:

circle_imag

🙂

This entry was posted in Algorithm, Vision and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*
*