annotate scripts/image/colormap.m @ 15683:806ea52af230

Overhaul m-files in image directory to provide better support for images stored as integers. * NEWS: Add note about overhaul of image scripts to support integer classes. * brighten.m: Add demo. * colormap.m: Better input validation. * contrast.m: Re-position window in demo. * gray2ind.m: Redo docstring. Match variables in docstring to function prototype. Better input validation. Return integer class outputs as Matlab does. Add %!tests. * hsv2rgb.m: Add to docstring. Better input validation. Redo algorithm to get rido of obsolete matrix-fill methods like kron(). Add %!tests. * image.m: Redo docstring. Match variables in docstring to function prototype. Better input validation without using for loops. * imagesc.m: Redo docstring. Match variables in docstring to function prototype. Remove DEPRECATEDZOOM functionality. Add demos. * imfinfo.m: Redo docstring. * ind2gray.m: Redo docstring. Match variables in docstring to function prototype. Redo algorithm to directly calculate luminance value rather than getting it from rgb2ntsc. Add %!tests. * ind2rgb.m: Redo docstring. Better input validation. Add some %!tests. * ntsc2rgb.m: Redo docstring. Better input validation. Add %!tests. * rgb2hsv.m: Better input validation. Add %!tests. * rgb2ind.m: Better input validation. Code algorithm in cleaner method for ease of understanding. * rgb2ntsc.m: Redo docstring: Better input validation. Add some %!tests.
author Rik <rik@octave.org>
date Tue, 27 Nov 2012 16:38:13 -0800
parents b9c02ee24de1
children b1cd65881592
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: 11523
diff changeset
1 ## Copyright (C) 1994-2012 John W. Eaton
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
2 ## Copyright (C) 2012 Carnë Draug
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
3 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
4 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
5 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
7 ## 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: 6895
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
9 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
10 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
14 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
15 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
16 ## 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: 6895
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6895
diff changeset
18 ## <http://www.gnu.org/licenses/>.
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 904
diff changeset
19
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3373
diff changeset
20 ## -*- texinfo -*-
14246
8b220af26cfb doc: Update docstring for colormap()
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
21 ## @deftypefn {Function File} {@var{cmap} =} colormap ()
8b220af26cfb doc: Update docstring for colormap()
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
22 ## @deftypefnx {Function File} {@var{cmap} =} colormap (@var{map})
8b220af26cfb doc: Update docstring for colormap()
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
23 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("default")
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
24 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("list")
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
25 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("register", "name")
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
26 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("unregister", "name")
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14246
diff changeset
27 ## Query or set the current colormap.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3381
diff changeset
28 ##
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3238
diff changeset
29 ## @code{colormap (@var{map})} sets the current colormap to @var{map}. The
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14246
diff changeset
30 ## colormap should be an @var{n} row by 3 column matrix. The columns
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3238
diff changeset
31 ## contain red, green, and blue intensities respectively. All entries
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14246
diff changeset
32 ## must be between 0 and 1 inclusive. The new colormap is returned.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3381
diff changeset
33 ##
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6762
diff changeset
34 ## @code{colormap ("default")} restores the default colormap (the
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6762
diff changeset
35 ## @code{jet} map with 64 entries). The default colormap is returned.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3381
diff changeset
36 ##
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
37 ## @code{colormap ("list")} returns a cell array with all the available
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
38 ## colormaps. The options `register' and `unregister' will add or remove the
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
39 ## colormap @var{name} to it.
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
40 ##
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3238
diff changeset
41 ## With no arguments, @code{colormap} returns the current color map.
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6762
diff changeset
42 ## @seealso{jet}
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3238
diff changeset
43 ## @end deftypefn
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
44
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 3106
diff changeset
45 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
46 ## Created: July 1994
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
47 ## Adapted-By: jwe
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 559
diff changeset
48
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
49 function cmap = colormap (map, name)
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
50
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
51 if (nargin > 2)
5923
611e30b984b3 [project @ 2006-08-14 18:29:18 by jwe]
jwe
parents: 5443
diff changeset
52 print_usage ();
1062
1b3a87031641 [project @ 1995-01-24 02:54:50 by jwe]
jwe
parents: 1024
diff changeset
53 endif
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
54
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
55 persistent map_list = cell ();
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
56
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 904
diff changeset
57 if (nargin == 1)
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
58
5443
ec8c33dcd1bf [project @ 2005-09-08 01:40:57 by jwe]
jwe
parents: 5307
diff changeset
59 if (ischar (map))
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 904
diff changeset
60 if (strcmp (map, "default"))
6895
76e3d985ae56 [project @ 2007-09-13 18:22:38 by jwe]
jwe
parents: 6762
diff changeset
61 map = jet (64);
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
62 elseif (strcmp (map, "list"))
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
63 cmap = map_list;
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
64 return;
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
65 else
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 5923
diff changeset
66 map = feval (map);
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
67 endif
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
68 endif
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
69
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
70 if (! isempty (map))
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14640
diff changeset
71 if (! ismatrix (map) || ndims (map) != 2 || columns (map) != 3)
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14640
diff changeset
72 error ("colormap: MAP must be an N x 3 ([R,G,B]) matrix");
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
73 endif
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14640
diff changeset
74 if (any (map(:) < 0) || any (map(:) > 1))
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14640
diff changeset
75 error ("colormap: all MAP values must be in the range [0,1]");
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
76 endif
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1887
diff changeset
77 ## Set the new color map
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 5923
diff changeset
78 set (gcf (), "colormap", map);
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
79 endif
3238
041ea33fbbf4 [project @ 1999-03-26 17:48:16 by jwe]
jwe
parents: 3202
diff changeset
80
14640
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
81 elseif (nargin == 2)
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
82 if (! ischar (map) || all (! strcmp (map, {"register", "unregister"})))
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
83 print_usage ();
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
84 elseif (! ischar (name))
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
85 error ("colormap: to register/unregister a colormap, NAME must be a string");
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
86 elseif (strcmp (map, "register"))
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
87 map_list{end+1} = name;
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
88 elseif (strcmp (map, "unregister"))
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
89 map_list(strcmp (name, map_list)) = [];
b9c02ee24de1 new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
90 endif
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
91 endif
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
92
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 1887
diff changeset
93 ## Return current color map.
7108
60a1165732f9 [project @ 2007-11-06 22:05:18 by jwe]
jwe
parents: 7017
diff changeset
94 if (nargout > 0 || (nargout == 0 && nargin == 0))
6762
721953d49b19 [project @ 2007-06-27 18:20:19 by jwe]
jwe
parents: 6257
diff changeset
95 cmap = get (gcf (), "colormap");
721953d49b19 [project @ 2007-06-27 18:20:19 by jwe]
jwe
parents: 6257
diff changeset
96 endif
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 904
diff changeset
97
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
98 endfunction
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14640
diff changeset
99
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14640
diff changeset
100
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14640
diff changeset
101 %%