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.
