How can I use the iswt2 from the wavelet toolbox with a different dwtmode?

6 次查看(过去 30 天)
The iswt2 is the inverse function of the swt2. In the swt2 the dwtmode is set to:
modeDWT = 'per';
I want to customize the swt2 to extend images in a symmetric manner, so changed the code to:
modeDWT = 'sym';
Unfortunately, I have not found an explicit parameter to consider the dwtmode in the iswt2. Is there a way to modify the iswt2 in this respect?

回答(1 个)

Umeshraja
Umeshraja 2024-8-8
编辑:Umeshraja 2024-9-21
I understand you are trying to use Symmetrization mode for 'swt2' and 'iswt2' function. According to MATLAB R2021a documentation, 'swt2' uses periodic extension:
However, you can symmetrically extend the images manually before performing transform using ‘swt2’ function and then remove the redundant coefficients after taking inverse wavelet transform. Assuming the application of performing the transform and reconstruction on a 2-D image, here's an example:
% Load example image from MATLAB documentation
load woman; % This loads the image 'X' into the workspace
portion=0.25; %Portion of image that can be extended symmetrically
% Symmetrically extend the image manually
X_extended = padarray(X, size(X)*portion, 'symmetric');
% Display the original and extended images
figure;
subplot(1, 2, 1);
imshow(X, []);
title('Original Image');
subplot(1, 2, 2);
imshow(X_extended, []);
title('Symmetrically Extended Image');
% Perform stationary wavelet transform on the extended image
wavelet = 'db1';
N = 2; % Level of decomposition
[A, H, V, D] = swt2(X_extended, N, wavelet);
% Perform inverse stationary wavelet transform
X_reconstructed_extended = iswt2(A, H, V, D, wavelet);
% Remove the redundant coefficients to get the original size
X_reconstructed = X_reconstructed_extended(size(X,1)*portion+1:end-size(X,1)*portion,...
size(X,2)*portion+1:end-size(X,2)*portion);
% Display the reconstructed image
figure;
imshow(X_reconstructed, []);
title('Reconstructed Image after Removing Redundant Coefficients', 'FontSize', 8);
% Sanity check if the reconstructed image is close to the original image
tolerance = 1e-12; % Define a small tolerance
mse = mean((X(:) - X_reconstructed(:)).^2);
if mse<tolerance
disp("Input image and Reconstructed image are same.")
else
disp("Reconstructed image differ.")
end
Input image and Reconstructed image are same.
For more information regarding ‘padarray’ function, Please refer to the following MATLAB R2021a documentation
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Signal Analysis 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by