Reputation: 11
I want to compare an image denoising method's performance using different wavelets and decomposition levels but I can't seem to incorporate the decomposition levels. Here's my current code (that works):
% Load dataset
original = imread('brain_mri_transversal_t2_001.jpg'); % original image filename
noisy = imread('mri_image_noisy.jpg'); % Load noisy image
% Apply wavelet transform
[LL, LH, HL, HH] = dwt2(noisy, 'db4');
% Define the threshold value
t = 200; % Adjust the threshold value as needed
%t = rbe*sqrt(2*log(1000)); % tuni VisuShrink
% Define the function for adaptive thresholding
function coeff_thresh = adaptive_thresholding(coeff, threshold, rbe)
if threshold == rbe
% Adaptive Hard Thresholding for t = rbe
coeff_thresh = zeros(size(coeff));
coeff_thresh(coeff < -threshold) = coeff(coeff < -threshold);
coeff_thresh(abs(coeff) <= threshold) = ...
rbe*(exp((-coeff(abs(coeff) <= threshold).^2)/(2*(rbe^2))-1/2)) - rbe*(exp((-0)/(2*(rbe^2))-1/2));
coeff_thresh(coeff > threshold) = coeff(coeff > threshold);
elseif threshold > rbe
% IMPROVED AGGD for t > rbe
coeff_thresh = zeros(size(coeff));
coeff_thresh(coeff < -threshold) = coeff(coeff < -threshold).*(1./(1+exp(coeff(coeff < -threshold)+threshold))-threshold/2);
coeff_thresh(abs(coeff) <= threshold) = ...
rbe*(exp((-coeff(abs(coeff) <= threshold).^2)/(2*(rbe^2))-1/2)) - rbe*(exp((-0)/(2*(rbe^2))-1/2));
coeff_thresh(coeff > threshold) = coeff(coeff > threshold).*(1./(1+exp(coeff(coeff > threshold)+threshold))+threshold/2);
end
end
% Robust median estimator
rbe = median(abs(HH(:)))/0.6745;
% Threshold the wavelet coefficients
HH_thresh = adaptive_thresholding(HH, t, rbe);
LH_thresh = adaptive_thresholding(LH, t, rbe);
HL_thresh = adaptive_thresholding(HL, t, rbe);
% Inverse wavelet transform
reconstructed = idwt2(LL, LH_thresh, HL_thresh, HH_thresh, 'db4');
I tried using wavedec2 and waverec2 but I always get some error about having too many input/output arguments, having not enough input arguments etc.
Upvotes: 1
Views: 46
Reputation: 2480
I'm not an expert on these libraries but the documentation of dwt2 says Single-level 2-D discrete wavelet transform. For a multi-level transform you would need to use wavedec2.
Upvotes: 0