]> Creatis software - CreaPhase.git/blob - octave_packages/m/image/brighten.m
update packages
[CreaPhase.git] / octave_packages / m / image / brighten.m
1 ## Copyright (C) 1999-2012 Kai Habel
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn  {Function File} {@var{map_out} =} brighten (@var{map}, @var{beta})
21 ## @deftypefnx {Function File} {@var{map_out} =} brighten (@var{h}, @var{beta})
22 ## @deftypefnx {Function File} {@var{map_out} =} brighten (@var{beta})
23 ## Darken or brighten the given colormap.  If the @var{map} argument
24 ## is omitted, the function is applied to the current colormap.  The first
25 ## argument can also be a valid graphics handle @var{h}, in which case
26 ## @code{brighten} is applied to the colormap associated with this handle.
27 ##
28 ## Should the resulting colormap @var{map_out} not be assigned, it will be
29 ## written to the current colormap.
30 ##
31 ## The argument @var{beta} should be a scalar between -1 and 1,
32 ## where a negative value darkens and a positive value brightens
33 ## the colormap.
34 ## @seealso{colormap}
35 ## @end deftypefn
36
37 function rmap = brighten (arg1, beta)
38   h = -1;
39   if (nargin == 1)
40     beta = arg1;
41     m = colormap;
42     h = gcf ();
43   elseif (nargin == 2)
44     if (ishandle (arg1))
45       h = arg1;
46       m = get (h, "colormap");
47     elseif (ismatrix (arg1) && columns (arg1) == 3)
48       m = arg1;
49     else
50       error ("brighten: first argument must be an Nx3 matrix or a handle");
51     endif
52   else
53     print_usage ();
54   endif
55
56   if (! isscalar (beta) || beta <= -1 || beta >= 1)
57     error ("brighten: BETA must be a scalar in the range (-1,1)");
58   endif
59
60   if (beta > 0)
61     gamma = 1 - beta;
62   else
63     gamma = 1 / (1 + beta);
64   endif
65
66   if (nargout == 0)
67     if (ishandle (h))
68       set (h, "colormap", m .^ gamma);
69     else
70       colormap (m .^ gamma);
71     endif
72   else
73     rmap = m .^ gamma;
74   endif
75
76 endfunction