Mercurial > hg > octave-image
view inst/private/make_conn.m @ 818:355bd9c476d9
bwperim: rewrite to support N-dimensional images and connectivity.
* bwperim.m: rewrite the function in order to accept images with any number
of dimensions. Treat the connectivity argument as more standard (relying on
the new private make_conn function). Display image instead of returning its
value if nargout less than 1. Add tests.
* private/make_conn.m: new private function to be shared among functions
accepting a connectivity argument.
* NEWS: add bwperim to functions that have been changed.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Tue, 29 Oct 2013 02:32:44 +0000 |
parents | |
children | 0ac3df9562b0 |
line wrap: on
line source
## Copyright (C) 2013 Carnë Draug <carandraug+dev@gmail.com> ## ## 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 3 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 <http://www.gnu.org/licenses/>. ## Private function to create a connectivity array ## ## Use the following Texinfo on the documentation of functions ## that make use of it (adjust the default) ## ## Element connectivity @var{conn}, to define the size of objects, can be ## specified with a numeric scalar (number of elements in the neighborhood): ## ## @table @samp ## @item 4 or 8 ## for 2 dimensional matrices; ## @item 6, 18 or 26 ## for 3 dimensional matrices; ## @end table ## ## or with a binary matrix representing a connectivity array. Defaults to ## @code{conndef (ndims (@var{bw}), "maximal")} which is equivalent to ## @var{conn} of 8 and 26 for 2 and 3 dimensional matrices respectively. function conn = make_conn (func, arg_pos, n_dims, conn) iptcheckconn (conn, func, "CONN", arg_pos); if (isscalar (conn)) if (n_dims == 2) if (conn == 4) conn = [0 1 0 1 1 1 0 1 0]; elseif (conn == 8) conn = [1 1 1 1 1 1 1 1 1]; else error ("%s: CONN must have a value of 4 or 8 for 2 dimensional matrices", func); endif elseif (n_dims == 3) if (conn == 6) conn = false (3, 3, 3); conn(:,2,2) = true; conn(2,:,2) = true; conn(2,2,:) = true; elseif (conn == 18) conn = false (3, 3, 3); conn(2,:,:) = true; conn(:,2,:) = true; conn(:,:,2) = true; elseif (conn == 26) conn = true (3, 3, 3); else error (["%s: CONN must have a value of 6, 18, or 26 for 3 " ... "dimensional matrices"], func); endif else error (["%s: CONN must be defined as a binary matrix for matrices " ... "with more than 3 dimensions"], func); endif endif endfunction