Mercurial > octave
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 |
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 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6788 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6788 | 18 |
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 | 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 | 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 | 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 | 33 ## @end deftypefn |
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 | 41 h = -1; |
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 | 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 | 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 | 54 endif |
55 endif | |
56 | |
8507 | 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 | 59 endif |
60 | |
61 if (beta > 0) | |
62 gamma = 1 - beta; | |
63 else | |
64 gamma = 1 / (1 + beta); | |
65 endif | |
66 | |
67 if (nargout == 0) | |
68 if (ishandle (h)) | |
69 set (h, "colormap", m .^ gamma); | |
70 else | |
71 colormap (m .^ gamma); | |
72 endif | |
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 | 75 endif |
76 | |
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 |