Pyramid method and Wavelet

Embed Size (px)

Citation preview

  • 7/24/2019 Pyramid method and Wavelet

    1/13

    REMOTE SENSING - DIGITAL IMAGE PROCESSING

    WAHYU RAHMANIAR

    102521604

    Computer Project 2: Pyramid method and Wavelet

    1. Pyramid methods:

    (1)Gaussian pyramid.

    A Gaussian pyramid is a technique to involves creating a series of images which are

    weighted down using a Gaussian average (Gaussian blur) and scaled down. When this

    technique is used multiple times, it creates a stack of successively smaller images, with

    each pixel containing a local average that corresponds to a pixel neighborhood on a lower

    level of the pyramid.

    In this project I used montana.lan as below:

    dir *.lanfid=fopen('montana.lan','r');fseek(fid,128,-1);A=fread(fid,[512*7 512],'uint8');B=A(512*3+1:512*4,:)';imagesc(B)title('paris')

    C=ones(size(B));% Gaussian Pyramidw=[.05 .25 .4 .25 .05];

    http://en.wikipedia.org/wiki/Gaussian_blurhttp://en.wikipedia.org/wiki/Gaussian_blur
  • 7/24/2019 Pyramid method and Wavelet

    2/13

    The Gaussian pyramid on image I is defined as:

    G0 (x,y) = I

    Gi+1 (x,y) = REDUCE (Gi(x,y))

    G1is low-pass filtered, and so may be encoded at a reduced sample rate. Further data

    compression is achieved by iterating this process.

    The reduce operation is carried out by convolving the image with a Gaussian low pass

    filter. The filter mask is designed such that the center pixel gets more weight than the

    neighboring ones and the remaining terms are chosen so that their sum is 1. The Gaussiankernel is given by: w = w-inverse * w, where, w = [.05 .25 .4 .25 .05].

    Pyramid construction is equivalent to convolving the original image with a set of

    Gaussian-like weighting functions. The convolution acts as a lowpass filter with the band

    limit reduced correspondingly by one octave with each level. Because of this

    resemblance to the Gaussian density function we refer to the pyramid of lowpass imagesas the "Gaussian pyramid."

    % ReduceW=w'*w;D=conv2(B,W,'same')./conv2(C,W,'same');G1=D(2:2:end,2:2:end);figureimagesc(G1)

    title('reduce')colormap(gray)

  • 7/24/2019 Pyramid method and Wavelet

    3/13

    Bandpass, rather than lowpass, images are required for many purposes. These may be

    obtained by subtracting each Gaussian (lowpass) pyramid level from the nextlower levelin the pyramid. Because these levels differ in their sample density it is necessary to

    interpolate new sample values between those in a given level before that level is

    subtracted from the next-lower level. Interpolation can be achieved by EXPAND

    operation.

    Gi+1 (x,y) = EXPAND (Gi(x,y))

    The expand operation is defined as follows:

    By repeating these steps several times a sequence of images expand 1, 2, and 3 are

    obtained. Levels of the Gaussian pyramid expanded to the size of the original image. The

    effects of lowpass filtering are now clearly apparent. The expand operation doubles the

    size of the image with each iteration, so that Gi,1, is the size of Gi,1, and Gi,1 is the same

    size as that of the original image. Examples of expanded Gaussian pyramid levels are

    shown in below:

    % ExpandF=zeros(512);F(2:2:end,2:2:end)=G1;imagesc(F)title('expand1')colormap(gray)H=4*conv2(F,W,'same')./conv2(C,W,'same');figureimagesc(H)title('expand2')colormap(gray)figureimagesc(B-H)title('expand3')colormap(gray)

  • 7/24/2019 Pyramid method and Wavelet

    4/13

  • 7/24/2019 Pyramid method and Wavelet

    5/13

    (2)Laplacian pyramid.

    The Laplacian pyramid can thus be used to represent images as a series of band-passfiltered images, each sampled at successively sparser densities. The levels of the

    Laplacian pyramid can be specified in terms of the lowpass pyramid levels as follows:

    Li= Gi- EXPAND (Gi(x,y))

    = GiGi+1

    dir *.lanfid=fopen('montana.lan','r');fseek(fid,128,-1);A=fread(fid,[512*7 512],'uint8');

    B=A(512*3+1:512*4,:)';imagesc(B)C=ones(size(B));

    w=[.05 .25 .4 .25 .05];W=w'*w;D=conv2(B,W,'same')./conv2(C,W,'same');G1=D(2:2:end,2:2:end);F=zeros(512);F(2:2:end,2:2:end)=G1;H=4*conv2(F,W,'same')./conv2(C,W,'same');

    % Laplacian

    L1=B-H;% Use for loopfori=1:6eval(['B=G',num2str(i),';'])C=ones(size(B));D=conv2(B,W,'same')./conv2(C,W,'same');G=D(2:2:end,2:2:end);eval(['G',num2str(i+1),'=G;'])F=zeros(size(G)*2);F(2:2:end,2:2:end)=G;H=4*conv2(F,W,'same')./conv2(C,W,'same');eval(['L',num2str(i+1),'=B-H;'])endfori=2:7subplot(3,2,i-1)eval(['imagesc(G',num2str(i),')'])endcolormap(gray)figurefori=2:7subplot(3,2,i-1)eval(['imagesc(L',num2str(i),')'])endcolormap(gray)

  • 7/24/2019 Pyramid method and Wavelet

    6/13

    Just as the value of each node in the Gaussian pyramid could have been obtained

    directly by convolving a Gaussian-like equivalent weighting function with the original

    image, each value of this bandpass pyramid could be obtained by convolving a difference

    of two Gaussians with the original image, this six levels are shown in the picture below:

    An important property of the Laplacian pyramid is that it is a complete imagerepresentation: the steps used to construct the pyramid may be reversed to recover the

    original image exactly. The top pyramid level, LN, is first expanded and added to LN-1

    to form GN-1 then this array is expanded and added to LN-2 to recover GN-2, and so on.

    The pyramid levels are obtained with fewer steps through repeated REDUCE and

    EXPAND operations that possible with the standard FFT.

    There are two reasons for transforming an image from one representation to another:

    the transformation may isolate critical components of the image pattern so they are more

    directly accessible to analysis, or the transformation may place the data in a more

    compact form so that they can be stored and transmitted more efficiently.

    The Laplacian pyramid serves both of these objectives. As a bandpass filter, pyramid

    construction tends to enhance image features, such as edges, which are important for

    interpretation. These features are segregated by scale in the various pyramid levels, as

    shown in picture below:

  • 7/24/2019 Pyramid method and Wavelet

    7/13

    As with the Fourier transform, pyramid code elements represent pattern components

    that are restricted in the spatial-frequency domain. But unlike the Fourier transform,

    pyramid code elements are also restricted to local regions in the spatial domain. Spatial as

    well as spatial-frequency localization can be critical in the analysis of images that contain

    multiple objects so that code elements will tend to represent characteristics of single

    objects rather than confound the characteristics of many objects.

    The coarsest scale of the Laplacian pyramid is the same as the Gaussian pyramid.

    Each of the finer layers are the difference between a layer of Gaussian pyramid and a

    prediction obtained by up-sampling the next coarsest layer of the Gaussian pyramid.

  • 7/24/2019 Pyramid method and Wavelet

    8/13

    (3)Recover the original image from its Laplacian pyramid:

    - Start from the coarsest scale of the pyramid (the smallest resolution)

    - Up-sample it.

    - Add it to the next coarsest scale of the Laplacian pyramid

    - Repeat the process until the finest level.

    figurefori=2:7

    subplot(1,2,i-1)%eval(['imagesc(L',num2str(i),')'])j = imresize(i, 0.8);x=j+i;eval(['imagesc(L',num2str(x),')'])colormap(gray)

    end

  • 7/24/2019 Pyramid method and Wavelet

    9/13

    2. Wavelet

    The point of doing Haar wavelet transform is that areas of the original matrix that

    contain little variation will end up as zero elements in the transformed matrix. A matrix is

    considered sparse if it has a high proportion of zero entries. Sparse matrices take much

    less memory to store.

    The first step of denoising is the application of filters. C1 denotes the low pass filter,

    while C2 denotes the high pass filter, like the picture below:

    fid=fopen('montana.lan','r');fseek(fid,128,-1);A=fread(fid,[512*7 512],'uint8');B=A(512*3+1:512*4,:)';

    % Harr Wavelet (Compare to Box pyramid)figuresubplot(1,2,1)% low-pass in horizontalC1=(B(:,1:2:end)+B(:,2:2:end))/2;imagesc(C1)title('lowpass')subplot(1,2,2)% high-pass in horizontalC2=(B(:,1:2:end)-B(:,2:2:end))/2;imagesc(C2)title('highpass')

  • 7/24/2019 Pyramid method and Wavelet

    10/13

    Thus, the low pass filter computes averages while the high pass filter accomplishes

    differencing. The process of differencing detects the noise in the signal. If some detailcoefficients are small compared to the others, making them zero will not alter the signal

    too much. If the noise is located in these areas of the signal, denoising will have a

    positive effect on the signal.

    This picture below show the low pass filter from low pass and high pass image before,

    and the high pass from from low pass and high pass image before.

    % low-pass and high-pass in verticalC11=(C1(1:2:end,:)+C1(2:2:end,:))/2;C12=(C1(1:2:end,:)-C1(2:2:end,:))/2;C21=(C2(1:2:end,:)+C2(2:2:end,:))/2;C22=(C2(1:2:end,:)-C2(2:2:end,:))/2;figure

    subplot(2,2,1)imagesc(C11)subplot(2,2,3)imagesc(C12)subplot(2,2,2)imagesc(C21)subplot(2,2,4)imagesc(C22)colormap(gray)B1=B;

  • 7/24/2019 Pyramid method and Wavelet

    11/13

    Then do the same, low pass (C1) and high pass (C2) filter from the low pass image

    C11 and high pass image C22.

    % Again for LL imageB=C11;C1=(B(:,1:2:end)+B(:,2:2:end))/2;C22=(C2(1:2:end,:)-C2(2:2:end,:))/2;C2=(B(:,1:2:end)-B(:,2:2:end))/2;C11=(C1(1:2:end,:)+C1(2:2:end,:))/2;

    C12=(C1(1:2:end,:)-C1(2:2:end,:))/2;C21=(C2(1:2:end,:)+C2(2:2:end,:))/2;C22=(C2(1:2:end,:)-C2(2:2:end,:))/2;figuresubplot(2,2,1)imagesc(C11)title('LL')subplot(2,2,3)imagesc(C12)title('LH')subplot(2,2,2)imagesc(C21)title('HL')

    subplot(2,2,4)imagesc(C22)title('HH')colormap(gray)

  • 7/24/2019 Pyramid method and Wavelet

    12/13

    Then we do the same filter like Wavelet image, but using Gaussian pyramid low pass

    filter (Dl) and high pass filter (Dh) like the picture below:

    % Wavelet compare to Gaussian pyramidB=B1;% low passwl=[.05 .25 .4 .25 .05];% high passwh=[0 0 1 0 0]-wl;

    D=conv2(B,wl,'same');Dl=D(:,2:2:end);D=conv2(B,wh,'same');Dh=D(:,2:2:end);DD=conv2(Dl,wl','same');Dll=DD(2:2:end,:);DD=conv2(Dl,wh','same');Dlh=DD(2:2:end,:);DD=conv2(Dh,wl','same');Dhl=DD(2:2:end,:);DD=conv2(Dh,wh','same');Dhh=DD(2:2:end,:);figuresubplot(2,2,1)imagesc(Dll)

    title('LL')subplot(2,2,3)imagesc(Dlh)

    title('LH')subplot(2,2,2)imagesc(Dhl)

    title('HL')subplot(2,2,4)imagesc(Dhh)

    title('HH')

  • 7/24/2019 Pyramid method and Wavelet

    13/13

    Using Gaussian pyramid we get darker image for HL and LH, but brighter image for

    LL and HH. The Gaussian pyramid result is much better than the Wavelet result. The

    result in Gaussian is more detail and we can see the edge of the image, but in Wavelet,

    the result in not clear enough to detect the edge. Images with different focal lengths will

    have different image regions in focus. Images with different shutter speeds may have

    different contrast and luminance levels in different regions.