Denoising function for a sliding DCT filter

12 views (last 30 days)
Deepika Sundresh
Deepika Sundresh on 15 Dec 2021
Edited: Abhimenyu on 14 Apr 2024 at 23:31
I am trying to build a function that denoises every channel of an image using DCT, and outputs the clean channel.
function denoised_ch = sliding_dct(channel, variance)
% choose window size as 8x8
fun1 = @(block_struct) dct2(block_struct.data(:));
dct_ch = blockproc(channel, [8 8], fun1);
[r, c] = size(dct_ch);
% threshold the DCT coeff with threshold = 3xvariance of the channel
fun2 = @(block_struct) idct2(block_struct.data(:));
denoised_ch = blockproc(channel, [8 8], fun2);
How can I implemement the part about thresholding? (The commented part)

Answers (1)

Abhimenyu
Abhimenyu on 14 Apr 2024 at 23:30
Edited: Abhimenyu on 14 Apr 2024 at 23:31
Hello,
From the information shared, I could infer that you are trying to implement thresholding in your function to modify the "DCT coefficients" based on the threshold, which is the "3 * variance" of the channel. The idea is to set the "DCT coefficients" that are below this threshold to zero, as they are likely to represent noise rather than signal. Please follow the below given example MATLAB code for the implementation of thresholding:
function denoised_ch = sliding_dct(channel, variance)
% Choose window size as 8x8
% Threshold Calculation: The threshold is calculated outside
% the block processing function as "3 * variance".
threshold = 3 * variance;
% Function to apply DCT and then threshold the coefficients
% thresholdDCT Function: This helper function applies the "2D DCT" to a block,
% then thresholds the "DCTthresholdDCT Function" coefficients by setting those that are below the
% absolute value of the threshold to zero.
fun1 = @(block_struct) thresholdDCT(block_struct.data, threshold);
% Apply DCT and thresholding within the block processing
% Block Processing for DCT and Thresholding: The blockproc function is used
% with fun1, which now points to the thresholdDCT function.
% This processes each 8x8 block of the channel, applying DCT and then thresholding.
dct_ch = blockproc(channel, [8 8], fun1);
% Function to apply inverse DCT
fun2 = @(block_struct) idct2(block_struct.data);
% Apply inverse DCT to get the denoised channel
denoised_ch = blockproc(dct_ch, [8 8], fun2);
end
% thresholdDCT Function
function dct_block = thresholdDCT(block, threshold)
% Apply DCT
dct_block = dct2(block);
% Apply thresholding
dct_block(abs(dct_block) < threshold) = 0;
end
The above-mentioned MATLAB code applies a threshold to each "DCT coefficient" with the help of the helper function "thresholdDCT" which applies the "dct2" MATLAB function for computing "DCT" and then thresholding to remove noise.
I hope this helps!

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!