X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=octave_packages%2Fimage-1.0.15%2Fordfilt2.m;fp=octave_packages%2Fimage-1.0.15%2Fordfilt2.m;h=073203d9b92b6ec484a988bcf1bbbd18262a91bb;hb=f5f7a74bd8a4900f0b797da6783be80e11a68d86;hp=0000000000000000000000000000000000000000;hpb=1705066eceaaea976f010f669ce8e972f3734b05;p=CreaPhase.git diff --git a/octave_packages/image-1.0.15/ordfilt2.m b/octave_packages/image-1.0.15/ordfilt2.m new file mode 100644 index 0000000..073203d --- /dev/null +++ b/octave_packages/image-1.0.15/ordfilt2.m @@ -0,0 +1,68 @@ +## Copyright (C) 2000 Teemu Ikonen +## +## This program is free software; you can redistribute it and/or +## modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 2 +## of the License, or (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; If not, see . + +## -*- texinfo -*- +## @deftypefn {Function File} {} ordfilt2(@var{A}, @var{nth}, @var{domain}, [@var{S}, @var{padding}]) +## Two dimensional ordered filtering. +## +## Ordered filter replaces an element of @var{A} with the @var{nth} +## element of the sorted set of neighbours defined by the logical +## (boolean) matrix @var{domain}. +## Neighbour elements are selected to the sort if the corresponding +## element in the @var{domain} matrix is true. +## +## The optional variable @var{S} is a matrix of size(@var{domain}). +## Values of @var{S} corresponding to nonzero values of domain are +## added to values obtained from @var{A} when doing the sorting. +## +## Optional variable @var{padding} determines how the matrix @var{A} +## is padded from the edges. See impad for details. +## +## @seealso{medfilt2} +## @end deftypefn + + +## Author: Teemu Ikonen +## Created: 5.5.2000 +## Keywords: image processing filtering + +function retval = ordfilt2(A, nth, domain, varargin) + +S = zeros(size(domain)); +padding = "zeros"; +for i=1:length(varargin) + a = varargin{:}; + if(ischar(a)) + padding = a; + elseif(ismatrix(a) && size(a) == size(domain)) + S = a; + endif +endfor + +domain = logical(domain); + +xpad(1) = floor((size(domain, 2)+1)/2) - 1; +xpad(2) = size(domain,2) - xpad(1) - 1; +ypad(1) = floor((size(domain, 1)+1)/2) - 1; +ypad(2) = size(domain,1) - ypad(1) - 1; + +if(ypad(1) >= size(A,1) || xpad(1) >= size(A,2)) + error("domain matrix too large"); +endif; + +A = impad(A, xpad, ypad, padding); +retval = __spatial_filtering__ (A, domain, "ordered", S, nth); + +endfunction