i m working on Bayes shrink will you please explain the code
38 views (last 30 days)
Show older comments
[thr,sorh,keepapp]= ddencmp('den', 'wv', noisyImage);
%% Wavelet Decomposition.
[C, S] = wavedec2(noisyImage, decomposingLevels, waveletFilterType);
display(S); %% Bayesian Thresholding.
ST = S(1, 1)^2 + 1; display(ST); bayesCoeff = [C(1 : ST-1), zeros(1, length(ST : 1 : length(C)))]; noiseVar = length(C)-S(size(S,1)-1,1)^2+1;
noiseSigma = median(abs(C(noiseVar : length(C)))) / 0.6745;
for index = 2 : size(S, 1) - 1
% H Coefficients.
coefH = C(ST : ST + S(index,1)^2 - 1);
thr = ProposedThreshold(coefH, noiseSigma);
bayesCoeff(ST : ST + S(index, 1)^2 - 1) = SoftThreshold(coefH,thr);
ST = ST + S(index, 1)^2;
% V Coefficients.
coefV = C(ST : ST + S(index, 1)^2 - 1);
thr = ProposedThreshold(coefV, noiseSigma);
bayesCoeff(ST : ST + S(index, 1)^2 - 1) = SoftThreshold(coefV,thr);
ST=ST+S(index,1)^2;
% D Coefficients.
coefD = C(ST : ST + S(index, 1)^2 - 1);
thr = ProposedThreshold(coefD, noiseSigma);
bayesCoeff(ST : ST + S(index, 1)^2 - 1) = SoftThreshold(coefD,thr);
ST = ST + S(index, 1)^2;
end
bayesImage = waverec2(bayesCoeff, S, waveletFilterType);
0 Comments
Answers (1)
Hari
on 18 Feb 2025
Hi Ashima,
This is the MATLAB code for denoising an image using wavelet decomposition and Bayesian thresholding.
I assume that the functions "ProposedThreshold" and "SoftThreshold" are defined elsewhere in your code or workspace, as they are not standard MATLAB functions.
Here is the explanation for the important steps:
Initial Setup and Wavelet Decomposition:
The code initializes parameters for denoising using ddencmp and performs a 2D wavelet decomposition on the noisy image using wavedec2.
[thr, sorh, keepapp] = ddencmp('den', 'wv', noisyImage);
[C, S] = wavedec2(noisyImage, decomposingLevels, waveletFilterType);
Calculate Noise Statistics:
The noise variance and sigma are estimated using the wavelet coefficients. The median function is used to estimate the noise level.
noiseVar = length(C) - S(size(S,1)-1,1)^2 + 1;
noiseSigma = median(abs(C(noiseVar : end))) / 0.6745;
Bayesian Thresholding:
The code iterates through the wavelet decomposition levels to apply Bayesian thresholding. For each level, horizontal (H), vertical (V), and diagonal (D) coefficients are thresholded.
for index = 2 : size(S, 1) - 1
% Process H, V, and D coefficients
coefH = C(ST : ST + S(index,1)^2 - 1);
thr = ProposedThreshold(coefH, noiseSigma);
bayesCoeff(ST : ST + S(index, 1)^2 - 1) = SoftThreshold(coefH, thr);
% Repeat for V and D coefficients
end
Reconstruction of Denoised Image:
The denoised image is reconstructed from the thresholded coefficients using waverec2.
bayesImage = waverec2(bayesCoeff, S, waveletFilterType);
Refer to the documentation of "ddencmp": https://www.mathworks.com/help/wavelet/ref/ddencmp.html
Refer to the documentation of "wavedec2": https://www.mathworks.com/help/wavelet/ref/wavedec2.html
Refer to the documentation of "waverec2": https://www.mathworks.com/help/wavelet/ref/waverec2.html
Hope this helps!
0 Comments
See Also
Categories
Find more on Uplink Physical Signals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!