Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Generating MATLAB Code for 2-D Stationary Wavelet Denoising

You can generate MATLAB® code to reproduce GUI-based 2-D stationary wavelet denoising at the command line. You can generate code to denoise both indexed and truecolor images. You must perform this operation in the SWT Denoising 2-D tool. You must first denoise your image before you can enable the File > Generate Matlab Code (Denoising Process) operation.

2-D Stationary Wavelet Transform Denoising

  1. Enter wavemenu at the MATLAB command prompt.

  2. Select SWT Denoising 2-D.

  3. Select File > Load Image, and load noiswom.mat from the matlab/toolbox/wavelet/wavedemo folder.

    Choose No when prompted to use the grayscale image.

  4. Select the db4 wavelet, and set the Level to 5.

  5. Click Decompose Image.

  6. Use the default soft thresholding method with Fixed form threshold and Unscaled white noise for Select noise structure.

  7. Set the following thresholds for the horizontal, diagonal, and vertical details. Ensure that you set the thresholds for the three detail coefficient types.

    • Level 1 — 5

    • Level 2 — 4

    • Level 3 — 3

    • Level 4 — 2

    • Level 5 — 1

  8. Click De-noise.

  9. Select File > Generate Matlab Code (Denoising Process).

    The operation generates the following MATLAB code.

    function [XDEN,wDEC] = func_denoise_sw2d(X)
    % FUNC_DENOISE_SW2D Saved Denoising Process.
    %   X: matrix of data
    %   -----------------
    %   XDEN: matrix of denoised data
    %   wDEC: stationary wavelet decomposition
    
    % Analysis parameters.
    %---------------------
    wname = 'db2';
    level = 5;
    
    % Denoising parameters.
    %-----------------------
    % meth = 'sqtwolog';
    % scal_OR_alfa = one;
    sorh = 's';    % Specified soft or hard thresholding
    thrSettings =  [...
        1.0000      2.0000      3.0000      4.0000      5.0000 ; ...
        1.0000      2.0000      3.0000      4.0000      5.0000 ; ...
        1.0000      2.0000      3.0000      4.0000      5.0000   ...
        ];
    roundFLAG = false;
    
    % Decompose using SWT2.
    %---------------------
    wDEC = swt2(X,level,wname);
    
    % Denoise.
    %---------
    permDir = [1 3 2];
    for j = 1:level
        for kk=1:3
            ind = (permDir(kk)-1)*level+j;
            thr = thrSettings(kk,j);
            wDEC(:,:,ind) = wthresh(wDEC(:,:,ind),sorh,thr);
        end
    end
    
    % Reconstruct the denoise signal using ISWT2.
    %-------------------------------------------
    XDEN = iswt2(wDEC,wname);
    if roundFLAG , XDEN = round(XDEN); end
  10. Save this MATLAB program as func_denoise_sw2d.m in a folder on the MATLAB search path.

    Execute the following code.

    load noiswom
    [XDEN,wDEC] = func_denoise_sw2d(X);
  11. Save the denoised image as denoisedwom.mat in a folder on the MATLAB search path.

  12. Execute the following code.

    load denoisedwom
    % Compare the GUI and command line results
    imagesc(X); title('GUI Operation'); colormap(gray);
    figure;
    imagesc(XDEN); title('Command Line Operation');
    colormap(gray);
    norm(XDEN-X,2)
Was this topic helpful?