Search code examples
matlabplothaar-wavelet

wavelet decomposition of a vector


If I have a hyperspectral data cube of size "m x n x p" where m is the row size, n represents the column size, while p is the total number of bands.

Lets denote the hyperspectral data cube by A. In this case, each pixel of A corresponds to a vector of size p x 1.

Ok to plot a pixel from A, we can do this:

specific_pixel = squeeze(A(x,y,:)); % Extracting a pixel located in the position x and y of A
plot(specific_pixel), ylabel('The specific pixel');

I have two questions:

1) I know how to plot each pixel separately like above, but how I can create a plot of all the pixels at meantime? for example if we have a 2D image, we can simply write plot(image). But for a datacube, how can we do this?

2) If I apply the 1D wavelet haar of 3 levels to the specific pixel above:

[c,s] = wavedec(A, 3, 'haar');
approxi = appcoef(c, s, 'haar', 3);
details3 = detcoef(c, s, 3);
details2 = detcoef(c, s, 2);
details1 = detcoef(c, s, 1);

How can I plot the concatenation of approxi and the three details??

Any help will be very appreciated.


Solution

  • If I understand you correctly, you wish to plot 3D data. You can either use scatter3 or plot3 to achieve what you want.

    With plot3, do:

    plot(A(:,:,1), A(:,:,2), A(:,:,3), 'b.', 'MarkerSize', 10);
    

    With scatter3 do:

    scatter3(A(:,:,1), A(:,:,2), A(:,:,3), 10, 'b');
    

    The above code plots each point in 3D space at size 10 and in the colour blue.

    With the second question, assuming that the output is also 3D, you can concatenate the cubes horizontally with cat, then repeat the above code.

    Something like this:

    out = cat(2, approxi, details1, details2, details3);
    
    plot(out(:,:,1), out(:,:,2), out(:,:,3), 'b.', 'MarkerSize', 10);
    %// or
    %// scatter3(out(:,:,1), out(:,:,2), out(:,:,3), 10, 'b');
    

    The 2 parameter in cat concatenates horizontally, so you'd be piecing 4 cubes together horizontally, but still maintaining the same amount of dimensions in the third dimension, and then just plotting all of them at the same time.