Mercurial > forge
changeset 11303:444f2894ba99 octave-forge
strel: implement height for arbitrary shapes
author | carandraug |
---|---|
date | Wed, 19 Dec 2012 10:45:19 +0000 |
parents | 65e4f5f66b9b |
children | ceb5d43b95d8 |
files | main/image/inst/@strel/getheight.m main/image/inst/@strel/isflat.m main/image/inst/@strel/strel.m |
diffstat | 3 files changed, 39 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/main/image/inst/@strel/getheight.m Mon Dec 17 21:54:50 2012 +0000 +++ b/main/image/inst/@strel/getheight.m Wed Dec 19 10:45:19 2012 +0000 @@ -23,6 +23,10 @@ function H = getheight (SE) - H = zeros (size (SE.nhood)); + if (SE.flat) + H = zeros (size (SE.nhood)); + else + H = SE.height; + endif endfunction
--- a/main/image/inst/@strel/isflat.m Mon Dec 17 21:54:50 2012 +0000 +++ b/main/image/inst/@strel/isflat.m Wed Dec 19 10:45:19 2012 +0000 @@ -28,6 +28,6 @@ ## strel included. function TF = isflat (SE) - TF = double(SE.flat); + TF = double (SE.flat); -endfunction \ No newline at end of file +endfunction
--- a/main/image/inst/@strel/strel.m Mon Dec 17 21:54:50 2012 +0000 +++ b/main/image/inst/@strel/strel.m Wed Dec 19 10:45:19 2012 +0000 @@ -54,22 +54,40 @@ shape = "arbitrary"; endif + ## because the order that these are created matters, we make them all here SE = struct; SE.shape = tolower (shape); + SE.nhood = false; + SE.flat = true; + SE.height = []; switch (SE.shape) case "arbitrary" if (numel (varargin) == 1) - nhood = varargin{1}; + nhood = varargin{1}; + SE.flat = true; + elseif (numel (varargin) == 2) + nhood = varargin{1}; + SE.height = varargin{2}; + SE.flat = false; else - ## TODO implement nonflat arbitrary (will take 2 arguments) - error ("strel: an arbitrary shape only takes 1 argument"); + error ("strel: an arbitrary shape takes 1 or 2 arguments"); endif if (! isbw (nhood, "non-logical")) error ("strel: NHOOD must be a matrix with only 0 and 1 values") endif - SE.nhood = logical (nhood); - SE.flat = false; + + SE.nhood = logical (nhood); # we need this as logical for the height tests + + if (! SE.flat && ! (isnumeric (SE.height) && isreal (SE.height) && + ndims (SE.height) == ndims (nhood) && + all (size (SE.height) == size (nhood)) && + all (isfinite (SE.height(:))))) + error ("strel: HEIGHT must be a finite real matrix of the same size as NHOOD"); + elseif (! SE.flat && ! (all (SE.height( SE.nhood)(:) > 0) && + all (SE.height(!SE.nhood)(:) == 0))) + error ("strel: HEIGHT must a matrix with values for each non-zero value in NHOOD"); + endif # case "ball" ## TODO implement ball shape @@ -167,13 +185,16 @@ endfunction function retval = is_positive_integer (val) - retval = isscalar(val) && isnumeric(val) && val > 0 && fix (val) == val; + retval = isscalar (val) && isnumeric (val) && val > 0 && fix (val) == val; endfunction -%!shared shape -%! shape = [0 0 0 1]; +%!shared shape, height +%! shape = [0 0 0 1]; %!assert (getnhood (strel (shape)), logical (shape)); %!assert (getnhood (strel ("arbitrary", shape)), logical (shape)); +%! height = [0 0 0 3]; +%!assert (getnhood (strel ("arbitrary", shape, height)), logical (shape)); +%!assert (getheight (strel ("arbitrary", shape, height)), height); %! shape = [0 0 0 1 0 0 0 %! 0 0 1 1 1 0 0 %! 0 1 1 1 1 1 0 @@ -209,6 +230,9 @@ %!error strel() %!error strel("nonmethodthing", 2) %!error strel("arbitrary", "stuff") +%!error strel("arbitrary", [0 0 1], [2 0 1]) +%!error strel("arbitrary", [0 0 1], [2 0 1; 4 5 1]) +%!error strel("arbitrary", [0 0 1], "stuff") %!error strel("diamond", -3) %!error strel("disk", -3) %!error strel("pair", [45 67 90])