2

I want to reconstruct an image from a multi-level DWT transform from only 5% of the largest coefficients while setting the rest to zero. I'm not sure which coefficients I need to choose the largest 5% from? A, H, V, or D?

Here is what I've done so far:

% Read image
x = imread('app.bmp'); 

% Define wavelet name
wavelet = 'haar';
% Define wavelet decomposition level
level = 4;
% Define colormap
map = gray;
% Compute multilevel 2D wavelet decomposition
[C, S] = wavedec2(x,level,wavelet);
for i = 1:levle
    % Approximation coefficients
    A = appcoef2(C,S,'haar',i);
    % Detailed coefficients
    [H,V,D] = detcoef2('all',C,S,i);
 end

Any help would be appreciated!

DML2014
  • 107
  • 1
  • 10

1 Answers1

0

In order to take the highest x% values of a matrix/vector this is what I usually do:

% define the threshold (5% here)
thr = 0.05;
% sort the variable in descending order
As = sort(A(:),'descend');
% obtain the elements belonging to the top x%
At = As(1:ceil(numel(As) * thr));

Now the At variable contains the top x% values of the matrix/vector A. Since you want to keep the original shape of A and set all its elements below the threshold to 0:

% take the minimum value of the result
Am = min(At);
% take the original matrix and set all the elements below the minimum top x% to zero:
A(A < Am) = 0;

and here you obtain the final form of your A matrix/vector.

Tommaso Belluzzo
  • 23,232
  • 8
  • 74
  • 98
  • Thank you for your answer, but what is A here? Which coefficients of which level? And when I reconstruct the image I should use waverec2, so which variables I should pass as C and S? – DML2014 Nov 30 '17 at 03:09
  • After trying the code you suggested, I don't think it works, as I think we need to pass the indices for A to be equal to zero in A(A < Am). But I'm not sure how to do that? – DML2014 Nov 30 '17 at 06:20