This file is indexed.

/usr/share/octave/packages/image-2.2.2/bwperim.m is in octave-image 2.2.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
## Copyright (C) 2013 Carnë Draug <carandraug@octave.org>
##
## 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/>.

## -*- texinfo -*-
## @deftypefn  {Function File} {} bwperim (@var{bw})
## @deftypefnx {Function File} {} bwperim (@var{bw}, @var{conn})
## Find perimeter of objects in binary images.
##
## Values from the matrix @var{bw} are considered part of an object perimeter
## if their value is non-zero and is connected to at least one zero-valued
## element.
##
## 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}), "minimal")} which is equivalent to
## @var{conn} of 4 and 6 for 2 and 3 dimensional matrices respectively.
##
## @seealso{bwarea, bwboundaries, imerode, mmgrad}
## @end deftypefn

function varargout = bwperim (bw, conn)

  if (nargin < 1 || nargin > 2)
    print_usage ();
  elseif (! ismatrix (bw) || ! (isnumeric (bw) || islogical (bw)))
    error("bwperim: BW must be a numeric matrix");
  endif

  nDims = ndims (bw);
  if (nargin < 2)
    ## Defining default connectivity here because it's dependent
    ## on the first argument
    conn = conndef (nDims, "minimal");
  else
    conn = make_conn ("bwperim", 2, nDims, conn);
  endif

  ## Make sure bw is logical;
  bw = logical (bw);

  ## Recover the elements that would get removed by erosion
  perim = (! imerode (bw, conn)) & bw;

  ## Get the borders back (they are removed during erosion
  tmp_idx = repmat ({":"}, [1 nDims]);
  p_size  = size (perim);
  for dim = 1:nDims
    idx       = tmp_idx;
    idx{dim}  = [1 p_size(dim)];
    perim(idx{:}) = bw(idx{:});
  endfor

  if (nargout > 0)
    varargout{1} = perim;
  else
    imshow (perim);
  endif
endfunction

%!shared in, out
%! in = [ 1   1   1   1   0   1   1   0   1   1
%!        1   1   0   1   1   1   1   1   1   0
%!        1   1   1   0   1   1   1   1   1   1
%!        1   1   1   1   0   1   1   1   0   1
%!        1   1   1   0   1   1   1   1   1   0
%!        1   1   1   1   1   1   0   1   0   1
%!        1   1   1   1   1   1   1   1   1   0
%!        1   1   1   1   1   1   1   1   1   1
%!        1   1   1   1   1   1   0   0   1   1
%!        1   1   1   1   0   1   0   1   1   0];
%!
%! out = [1   1   1   1   0   1   1   0   1   1
%!        1   1   0   1   1   0   0   1   1   0
%!        1   0   1   0   1   0   0   0   1   1
%!        1   0   0   1   0   1   0   1   0   1
%!        1   0   1   0   1   0   1   0   1   0
%!        1   0   0   1   0   1   0   1   0   1
%!        1   0   0   0   0   0   1   0   1   0
%!        1   0   0   0   0   0   1   1   0   1
%!        1   0   0   0   1   1   0   0   1   1
%!        1   1   1   1   0   1   0   1   1   0];
%!assert (bwperim (in), logical (out));
%!assert (bwperim (in, 4), logical (out));
%!
%! out = [1   1   1   1   0   1   1   0   1   1
%!        1   1   0   1   1   1   1   1   1   0
%!        1   1   1   0   1   1   0   1   1   1
%!        1   0   1   1   0   1   0   1   0   1
%!        1   0   1   0   1   1   1   1   1   0
%!        1   0   1   1   1   1   0   1   0   1
%!        1   0   0   0   0   1   1   1   1   0
%!        1   0   0   0   0   1   1   1   1   1
%!        1   0   0   1   1   1   0   0   1   1
%!        1   1   1   1   0   1   0   1   1   0];
%!assert (bwperim (in, 8), logical (out));
%!
%! out = [1   1   1   1   0   1   1   0   1   1
%!        1   0   0   0   0   1   0   0   1   0
%!        1   0   0   0   0   0   0   1   0   1
%!        1   0   1   0   0   0   0   0   0   1
%!        1   0   0   0   0   1   0   1   0   0
%!        1   0   0   0   1   0   0   0   0   1
%!        1   0   0   0   0   0   0   1   0   0
%!        1   0   0   0   0   1   1   0   0   1
%!        1   0   0   1   0   1   0   0   1   1
%!        1   1   1   1   0   1   0   1   1   0];
%!assert (bwperim (in, [1 0 0; 0 1 0; 0 0 1]), logical (out));

## test that any non-zero value is valid (even i and Inf)
%!shared in, out
%! in = [ 0   0   0   0   0   0   0
%!        0   0   5   0   0   1   9
%!        0 Inf   9   7   0   0   0
%!        0 1.5   5   7   1   0   0
%!        0 0.5  -1  89   i   0   0
%!        0   4  10  15   1   0   0
%!        0   0   0   0   0   0   0];
%! out = [0   0   0   0   0   0   0
%!        0   0   1   0   0   1   1
%!        0   1   0   1   0   0   0
%!        0   1   0   0   1   0   0
%!        0   1   0   0   1   0   0
%!        0   1   1   1   1   0   0
%!        0   0   0   0   0   0   0];
%!assert (bwperim (in), logical (out));

## test for 3D
%!shared in, out
%! in = reshape (magic(16), [8 8 4]) > 50;
%! out(:,:,1) = [
%!    1   1   0   1   0   1   1   1
%!    0   1   1   1   1   1   0   1
%!    0   1   1   1   1   1   0   1
%!    1   1   0   1   1   1   1   1
%!    1   1   1   1   1   1   1   1
%!    1   1   1   0   1   0   1   1
%!    1   1   1   0   1   0   1   1
%!    1   0   1   1   1   1   1   0];
%! out(:,:,2) = [
%!    1   1   0   1   0   1   1   1
%!    0   1   1   0   1   1   0   1
%!    0   1   0   0   0   1   0   1
%!    1   0   1   0   0   0   1   1
%!    1   0   0   1   0   1   0   1
%!    1   0   1   0   1   0   1   1
%!    1   1   1   0   1   0   1   1
%!    1   0   1   1   1   1   1   0];
%! out(:,:,3) = [
%!    1   1   0   1   0   1   1   1
%!    0   1   1   0   1   1   0   1
%!    0   1   0   0   0   1   0   1
%!    1   0   0   0   0   0   1   1
%!    1   0   0   1   0   1   0   1
%!    1   0   1   0   1   0   1   1
%!    1   1   1   0   1   0   1   1
%!    1   0   1   1   1   1   1   0];
%! out(:,:,4) = [
%!    1   1   0   1   0   1   1   1
%!    0   1   1   1   1   1   0   1
%!    0   1   1   1   1   1   0   1
%!    1   1   1   1   1   1   1   1
%!    1   1   1   1   1   1   1   0
%!    1   1   1   0   1   0   1   1
%!    1   1   1   0   1   0   1   1
%!    1   0   1   1   1   1   1   0];
%!assert (bwperim (in), logical (out));
%!
%! out(:,:,1) = [
%!    1   1   0   1   0   1   1   1
%!    0   1   1   1   1   1   0   1
%!    0   1   1   1   1   1   0   1
%!    1   1   0   1   1   1   1   1
%!    1   1   1   1   1   1   1   1
%!    1   1   1   0   1   0   1   1
%!    1   1   1   0   1   0   1   1
%!    1   0   1   1   1   1   1   0];
%! out(:,:,2) = [
%!    1   1   0   1   0   1   1   1
%!    0   1   1   1   1   1   0   1
%!    0   1   1   0   0   1   0   1
%!    1   1   1   1   0   1   1   1
%!    1   0   1   1   1   1   1   1
%!    1   0   1   0   1   0   1   1
%!    1   1   1   0   1   0   1   1
%!    1   0   1   1   1   1   1   0];
%! out(:,:,3) = [
%!    1   1   0   1   0   1   1   1
%!    0   1   1   1   1   1   0   1
%!    0   1   0   0   0   1   0   1
%!    1   1   0   0   0   1   1   1
%!    1   0   1   1   1   1   1   1
%!    1   0   1   0   1   0   1   1
%!    1   1   1   0   1   0   1   1
%!    1   0   1   1   1   1   1   0];
%! out(:,:,4) = [
%!    1   1   0   1   0   1   1   1
%!    0   1   1   1   1   1   0   1
%!    0   1   1   1   1   1   0   1
%!    1   1   1   1   1   1   1   1
%!    1   1   1   1   1   1   1   0
%!    1   1   1   0   1   0   1   1
%!    1   1   1   0   1   0   1   1
%!    1   0   1   1   1   1   1   0];
%!assert (bwperim (in, 18), logical (out));

%!error bwperim ("text")
%!error bwperim (rand (10), 5)
%!error bwperim (rand (10), "text")