%
% [Soille02] P. Soille: "On morphological operators based on rank filters",% Pattern Recognition, 35:527-535, 2002.
% %
% [Yaros08] L. Yaroslavsky: "Local criteria and local adaptive filtering% in image processing: a retrospective view", Proc. LNLAIP, 2008.
% %
%% Credit% (ISR-2/LANL)
% %% See also
% Ressembles:% ,
% ,% .
% Requires:% .
%% Function implementation
function WOI = wordfilt2(I,wk,varargin)
error(nargchk(2, 4, nargin, 'struct'));error(nargoutchk(1, 1, nargout, 'struct'));
%%
% parsing and checking parametersif ~isnumeric(I)
error('wordfilt2:inputerror','matrice is required in input');end
p = createParser('WORDFILT2'); % create an instance of the inputParser class.
% optional parametersp.addOptional('order','med', @(x) (isscalar(x) && x>0) ||...
(ischar(x)&& any(strcmpi(x,{'med','mod'}))));
% parse and validate all input argumentsp.parse(varargin{:});
p = getvarParser(p);
%%% internal variables and further checking
C = size(I,3);
[x y c] = size(wk);s = sum(abs(wk(:)));
if ~isequal(round(wk),wk)
warning('wordfilt2:inputwarning',... 'the input weighting matrix must have integer values');
end
if isscalar(p.order) && p.order>s error('wordfilt2:inputerror',...
'the input rank must be <= to the sum of the elements in wk');end
if c~=1 && c~=C
error('wordfilt2:inputargument', ... 'input kernel must have 1 channel or the same number as the input');
end
cpos = find(wk<0,1,'first');if isempty(cpos) && (x~=y || mod(x,2)~=1)
error('wordfilt2:inputargument',... 'input kernel must be square shaped with odd size');
end
%%% main processing
WOI = wordfilt2_base(I, wk, p.order);
%%
% display
if p.disp figure, imagesc(rescale(WOI,0,1)), axis image off;
if C==1, colormap gray; end; title('weighted order-statistic filtered image');
end
end % end of wordfilt2
##### SOURCE END #####-->