# I am getting "Too few input arguments." error. How can i solve it?

2 views (last 30 days)
Berkay YABAN on 13 May 2021
Edited: per isakson on 13 May 2021
function [f,noise] = wieneredg(varargin)
[g, nhood, block, noise, msg] = ParseInputs(varargin{:});
if (~isempty(msg))
error(msg);
end
classin = class(g);
classChanged = 0;
if ~isa(g, 'double')
classChanged = 1;
g = im2double(g);
end
% Estimate the local mean of f.
localMean = filter2(ones(nhood), g) / prod(nhood);
% Estimate of the local variance of f.
localVar = filter2(ones(nhood), g.^2) / prod(nhood) - localMean.^2;
% Estimate the noise power if necessary.
if (isempty(noise))
noise = mean(localVar(:));
end
% Compute result
% f = localMean + (max(0, localVar - noise) ./ ...
% max(localVar, noise)) .* (g - localMean);
%
% Computation is split up to minimize use of memory
% for temp arrays.
f = g - localMean;
g = localVar - noise;
g = max(g, 0);
localVar = max(localVar, noise);
f = f ./ localVar;
f = f .* g;
f = f + localMean;
%%%
%%% Subfunction ParseInputs
%%%
function [g, nhood, block, noise, msg] = ParseInputs(varargin)
g = [];
nhood = [3 3];
block = [];
noise = [];
msg = '';
switch nargin
case 0
msg = 'Too few input arguments.';
return;
case 1
% wieneredg(I)
g = varargin{1};
case 2
g = varargin{1};
switch prod(size(varargin{2}))
case 1
% wieneredg(I,noise)
noise = varargin{2};
case 2
% wieneredg(I,[m n])
nhood = varargin{2};
otherwise
msg = 'Invalid input syntax';
return;
end
case 3
g = varargin{1};
if (prod(size(varargin{3})) == 2)
% wieneredg(I,[m n],[mblock nblock]) OBSOLETE
warning(['WIENEREDG(I,[m n],[mblock nblock]) is an obsolete syntax.',...
'Omit the block size, the image matrix is processed all at once.']);
nhood = varargin{2};
block = varargin{3};
else
% wieneredg(I,[m n],noise)
nhood = varargin{2};
noise = varargin{3};
end
case 4
% wieneredg(I,[m n],[mblock nblock],noise) OBSOLETE
warning(['WIENEREDG(I,[m n],[mblock nblock],noise) is an obsolete syntax.',...
'Omit the block size, the image matrix is processed all at once.']);
g = varargin{1};
nhood = varargin{2};
block = varargin{3};
noise = varargin{4};
otherwise
msg = 'Too many input arguments.';
return;
end
% checking if input image is a truecolor image-not supported by WIENER2
if (ndims(g) == 3)
msg = 'WIENEREDG does not support 3D truecolor images as an input.';
return;
end;
if (isempty(block))
block = bestblk(size(g));
end
%%%%Output
J = imnoise(I,'gaussian',0,0.005);
K = wieneredg(J,[5 5]);
imshow(J), figure, imshow(K)
##### 2 CommentsShowHide 1 older comment
Berkay YABAN on 13 May 2021

per isakson on 13 May 2021
Edited: per isakson on 13 May 2021
And see narginchk - Validate number of input arguments.