DnCNN - how does denoiseImage work?
5 views (last 30 days)
Show older comments
I have a question related to DnCNN. The architecture of DnCNN has the input image layer with the size of [50,50,1]. But when using the trained model for prediction by using the function denoiseImage, it can be applied to images of arbitrary sizes. Meawhile, I can't do the same thing by using the function predict since the input image and the input layer have different sizes. Anyone can explain me how the function denoiseImage works. Does it divide the input image into patches or replace the input image layer? Thank you.
0 Comments
Answers (1)
Gayathri
on 4 Jun 2025
As of MATLAB R2024b, I am able to use both "denoiseImage" and "predict" function, without any errors for different image dimensions when using the pretrained "DnCNN" model.
Please refer to the below code which illustrates the same.
% Load pre-trained DnCNN model
net = denoisingNetwork('dncnn'); % Loads MATLAB's pre-trained DnCNN for Gaussian noise
% Read input image
inputImagePath = 'mri.tif'; % Replace with your image path
I = imread(inputImagePath);
disp(size(I));
% Convert to grayscale if needed (DnCNN typically works on grayscale images)
if size(I, 3) == 3
I = rgb2gray(I);
end
I = im2double(I); % Convert to double for processing (range [0, 1])
% Add synthetic Gaussian noise
noiseLevel = 25 / 255; % Noise standard deviation
noisyI = imnoise(I, 'gaussian', 0, noiseLevel^2);
out=predict(net, noisyI);
disp("Predict function worked")
% Denoise the image using DnCNN
denoisedI = denoiseImage(noisyI, net);
disp("denoiseImage function worked")
What I understand is that, "denoiseImage" function do not work on patches and work on the whole image. It uses the predict function to make the predictions.
You can read more about "denoiseImage" function using the link below.
0 Comments
See Also
Categories
Find more on Deep Learning for Image Processing 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!