]> Creatis software - CreaPhase.git/blob - octave_packages/image-1.0.15/imcomplement.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / image-1.0.15 / imcomplement.m
1 ## Copyright (C) 2008 Soren Hauberg
2 ##
3 ## This program is free software; you can redistribute it and/or
4 ## modify it under the terms of the GNU General Public License
5 ## as published by the Free Software Foundation; either version 3
6 ## of the License, or (at your option) any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 ## General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} @var{B} = imcomplement(@var{A})
18 ## Computes the complement image. Intuitively this corresponds to the intensity
19 ## of bright and dark regions being reversed.
20 ##
21 ## For binary images, the complement is computed as @code{!@var{A}}, for floating
22 ## point images it is computed as @code{1 - @var{A}}, and for integer images as
23 ## @code{intmax(class(@var{A})) - @var{A}}.
24 ## @end deftypefn
25
26 function B = imcomplement(A)
27   ## Check input
28   if (nargin != 1)
29     error("imcomplement: not enough input arguments");
30   endif
31   if (!ismatrix(A))
32     error("imcomplement: input must be an array");
33   endif
34
35   ## Take action depending on the class of A
36   if (isa(A, "double") || isa(A, "single"))
37     B = 1 - A;
38   elseif (islogical(A))
39     B = !A;
40   elseif (isinteger(A))
41     B = intmax(class(A)) - A;
42   else
43     error("imcomplement: unsupported input class: '%s'", class(A));
44   endif
45 endfunction