Best way to perform a 2D (inverse) Wavelet transform on each slice of a tensor? (lwt2, dwt2 failing)

2 次查看(过去 30 天)
Hello,
I am trying to perform a 2D Wavelet transform on each frame of a video right now and I am having issues with the standard functions from the wavelet toolbox: lwt2, ilwt2, dwt2, idwt2. I want to use them to increase/decrease the resolution by a factor of 2.
They seem to assume that the input tensor is actually a RGB image, so they assume that the third dimension is length 3. Either the methods crash or they truncate the data. Is there any way to perform a 2D transform on the tensor? Something like many other Matlab functions have, where you specify the dimensions you want to perform the transform on?
I know I could run the transform on each frame seperately using cellfun or a loop, but the process is time critical and I don't want an overloaded and slow solution.
D = randn(64,64,64); % some random data
% try downsampling using dwt2
[X,~,~,~] = dwt2(D,'db6','mode','per');
whos X % has dimensions 32x32x3, so the 3rd dimension got truncated
% try upsampling using idwt
Y = idwt2(D,zeros(size(D)),zeros(size(D)),zeros(size(D)),'db6','mode','per');
whos Y % again Y has dimensions 128x128x3, so 3rd dimension got truncated
% try the same with lwt2 and ilwt2
[P,~,~,~] = lwt2(D,'db6');
whos P % this actually works, P has dimensions 32x32x64
% upsampling just crashed because of a dimension missmatch (again Matlab
% assumes and image here)
Q = ilwt2(D,zeros(size(D)),zeros(size(D)),zeros(size(D)),'db6');
In the above example I would like the wavelet transform to be applied on each frame, i.e., in the end X and P should have size 32x32x64 and Y and Q should have size 128x128x64.
  1 个评论
Sharmin Kibria
Sharmin Kibria 2023-8-18
Hi,
In your question you said that you want to reduce the resolution by a factor of 2. So why are you using wavelet transform for that purpose? Shouldn't resample suffice in the case?
The output that you are getting out of the transforms are the low frequency components downsampled by 2. Also, the results returned by dwt2 and lwt2 are different because the former returns the signal after performing one level of decomposition and the latter performed min(size(x,[1 2])/2) level of decomposition.
The command for ilwt2 should crash because you are supplying the coefficients after D as matrices. ilwt2 expects the inputs to be cell arrays. Please see ilwt2 documentation for this. Again, ilwt2 is not a tool for upsampling. It will assume D to be the low frequency component and try to reconstruct the signal after filtering with low pass filters.
I hope my comment clarifies your concerns.
Thanks
Sharmin

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Wavelet Toolbox 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by