X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=octave_packages%2Fimage-1.0.15%2Fimcomplement.m;fp=octave_packages%2Fimage-1.0.15%2Fimcomplement.m;h=6d4840e5d20112d0eb35b5c36b7e4e481ac3557f;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hp=0000000000000000000000000000000000000000;hpb=1705066eceaaea976f010f669ce8e972f3734b05;p=CreaPhase.git diff --git a/octave_packages/image-1.0.15/imcomplement.m b/octave_packages/image-1.0.15/imcomplement.m new file mode 100644 index 0000000..6d4840e --- /dev/null +++ b/octave_packages/image-1.0.15/imcomplement.m @@ -0,0 +1,45 @@ +## Copyright (C) 2008 Soren Hauberg +## +## 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 . + +## -*- texinfo -*- +## @deftypefn {Function File} @var{B} = imcomplement(@var{A}) +## Computes the complement image. Intuitively this corresponds to the intensity +## of bright and dark regions being reversed. +## +## For binary images, the complement is computed as @code{!@var{A}}, for floating +## point images it is computed as @code{1 - @var{A}}, and for integer images as +## @code{intmax(class(@var{A})) - @var{A}}. +## @end deftypefn + +function B = imcomplement(A) + ## Check input + if (nargin != 1) + error("imcomplement: not enough input arguments"); + endif + if (!ismatrix(A)) + error("imcomplement: input must be an array"); + endif + + ## Take action depending on the class of A + if (isa(A, "double") || isa(A, "single")) + B = 1 - A; + elseif (islogical(A)) + B = !A; + elseif (isinteger(A)) + B = intmax(class(A)) - A; + else + error("imcomplement: unsupported input class: '%s'", class(A)); + endif +endfunction