annotate scripts/image/brighten.m @ 17692:38cf56b77274

Overhaul image, imagesc to use newplot and support low-level invocation form. * scripts/image/image.m: New variable do_new indicates high-level calling form. For high-level invocation, call newplot before __img__. Correct linearity check if vectors are reversed (high-to-low values). Only apply image properties to axes if doing a high-level invocation. * scripts/image/imagesc.m: New variable do_new indicates high-level calling form. Delete subfunction __imagesc__ and incorporate minimal amount of code into imagesc. Only apply climits for high-level invocation.
author Rik <rik@octave.org>
date Fri, 18 Oct 2013 16:27:44 -0700
parents b1cd65881592
children d63878346099
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 12575
diff changeset
1 ## Copyright (C) 1999-2012 Kai Habel
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
2 ##
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
3 ## This file is part of Octave.
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
4 ##
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6792
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6792
diff changeset
8 ## your option) any later version.
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
9 ##
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
13 ## General Public License for more details.
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
14 ##
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6792
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6792
diff changeset
17 ## <http://www.gnu.org/licenses/>.
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
18
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
19 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10606
diff changeset
20 ## @deftypefn {Function File} {@var{map_out} =} brighten (@var{map}, @var{beta})
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
21 ## @deftypefnx {Function File} {@var{map_out} =} brighten (@var{beta})
6792
bbe79d3ed56a [project @ 2007-07-24 20:34:08 by dbateman]
dbateman
parents: 6791
diff changeset
22 ## @deftypefnx {Function File} {@var{map_out} =} brighten (@var{h}, @var{beta})
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
23 ## Brighten or darken a colormap. If the @var{map} argument is omitted, the
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
24 ## function is applied to the current colormap. The first argument can also be
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
25 ## a valid graphics handle @var{h}, in which case @code{brighten} is applied to
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
26 ## the colormap associated with this handle.
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
27 ##
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
28 ## The argument @var{beta} must be a scalar between -1 and 1, where a
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
29 ## negative value darkens and a positive value brightens the colormap.
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
30 ##
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
31 ## If no output is specified then the result is written to the current colormap.
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
32 ## @seealso{colormap, contrast}
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
33 ## @end deftypefn
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
34
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
35 function rmap = brighten (arg1, beta)
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
36
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
37 if (nargin < 1 || nargin > 2)
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
38 print_usage ();
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
39 endif
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
40
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
41 h = -1;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
42 if (nargin == 1)
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
43 beta = arg1;
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
44 m = colormap ();
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
45 h = gcf ();
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
46 else
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
47 if (ishandle (arg1))
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
48 h = arg1;
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
49 m = get (h, "colormap");
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
50 elseif (iscolormap (arg1))
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
51 m = arg1;
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
52 else
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15683
diff changeset
53 error ("brighten: first argument must be a colormap or a graphics handle");
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
54 endif
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
55 endif
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
56
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
57 if (! isscalar (beta) || beta <= -1 || beta >= 1)
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11469
diff changeset
58 error ("brighten: BETA must be a scalar in the range (-1,1)");
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
59 endif
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
60
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
61 if (beta > 0)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
62 gamma = 1 - beta;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
63 else
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
64 gamma = 1 / (1 + beta);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
65 endif
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
66
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
67 if (nargout == 0)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
68 if (ishandle (h))
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
69 set (h, "colormap", m .^ gamma);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
70 else
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
71 colormap (m .^ gamma);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
72 endif
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
73 else
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
74 rmap = m .^ gamma;
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
75 endif
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
76
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents:
diff changeset
77 endfunction
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
78
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
79
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
80 %!demo
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
81 %! ## First figure uses default grayscale colormap
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
82 %! figure;
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
83 %! colormap (gray (64));
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
84 %! image (1:64, linspace (0, 1, 64), repmat ((1:64)', 1, 64));
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
85 %! axis ([1, 64, 0, 1], "ticy", "xy");
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
86 %! title ("default grayscale colormap");
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
87 %! pos = get (gcf, "position");
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
88 %! pos(1) += pos(3) + 25;
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
89 %! ## Second figure uses brightened grayscale colormap
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
90 %! figure ("position", pos);
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
91 %! colormap (gray (64));
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
92 %! image (1:64, linspace (0, 1, 64), repmat ((1:64)', 1, 64));
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
93 %! axis ([1, 64, 0, 1], "ticy", "xy");
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
94 %! brighten (0.5);
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
95 %! title ("grayscale colormap brightened by 0.5");
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
96