annotate scripts/image/ind2rgb.m @ 13279:984359717d71

Use common code idiom for checking whether a double value is an integer. * num2str.m, rotdim.m, get_first_help_sentence.m, ind2rgb.m, commutation_matrix.m, figure.m, legend.m, polyfit.m, bartlett.m, blackman.m, detrend.m, hamming.m, hanning.m, factorial.m, mode.m, skewness.m, statistics.m, mcnemar_test.m: Use idiom 'x == fix (x)' to test for integerness.
author Rik <octave@nomad.inbox5.com>
date Wed, 05 Oct 2011 13:10:10 -0700
parents c792872f8942
children 72c96de7a403
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11472
diff changeset
1 ## Copyright (C) 1994-2011 John W. Eaton
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
2 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
3 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
4 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
5 ## 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
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: 6247
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: 6247
diff changeset
8 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
9 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
10 ## 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
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
12 ## 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
13 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
14 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
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: 6247
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: 6247
diff changeset
17 ## <http://www.gnu.org/licenses/>.
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
18
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3373
diff changeset
19 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 7017
diff changeset
20 ## @deftypefn {Function File} {@var{rgb} =} ind2rgb (@var{x}, @var{map})
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
21 ## @deftypefnx {Function File} {[@var{R}, @var{R}, @var{R}] =} ind2rgb (@var{x}, @var{map})
2311
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
22 ## Convert an indexed image to red, green, and blue color components.
6247
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
23 ## If the colormap doesn't contain enough colors, pad it with the
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
24 ## last color in the map.
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3202
diff changeset
25 ## If @var{map} is omitted, the current colormap is used for the conversion.
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5307
diff changeset
26 ## @seealso{rgb2ind, image, imshow, ind2gray, gray2ind}
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3202
diff changeset
27 ## @end deftypefn
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 559
diff changeset
28
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 2847
diff changeset
29 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
30 ## Created: July 1994
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
31 ## Adapted-By: jwe
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
32
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
33 function [R, G, B] = ind2rgb (x, map)
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
34
6247
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
35 ## Do we have the right number of inputs?
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
36 if (nargin < 1 || nargin > 2)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5775
diff changeset
37 print_usage ();
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
38 elseif (nargin == 1)
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
39 map = colormap ();
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
40 endif
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
41
6247
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
42 ## Check if X is an indexed image.
13279
984359717d71 Use common code idiom for checking whether a double value is an integer.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
43 if (ndims (x) != 2 || any (x(:) != fix (x(:))) || min (x(:)) < 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
44 error ("ind2rgb: X must be an indexed image");
6247
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
45 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
46
6247
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
47 ## Check the color map.
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
48 if (ndims (map) != 2 || columns (map) != 3)
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
49 error ("ind2rgb: MAP must be a valid colormap");
6247
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
50 endif
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
51
6247
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
52 ## Do we have enough colors in the color map?
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
53 maxidx = max (x(:));
6247
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
54 rm = rows (map);
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
55 if (rm < maxidx)
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
56 ## Pad with the last color in the map.
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
57 pad = repmat (map(end,:), maxidx-rm, 1);
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
58 map(end+1:maxidx, :) = pad;
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
59 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
60
6247
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
61 ## Compute result
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
62 [hi, wi] = size (x);
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
63 R = reshape (map (x(:), 1), hi, wi);
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
64 G = reshape (map (x(:), 2), hi, wi);
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
65 B = reshape (map (x(:), 3), hi, wi);
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
66
6247
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
67 ## Use 3D array if only one output is requested.
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
68 if (nargout <= 1)
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
69 R(:,:,3) = B;
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
70 R(:,:,2) = G;
7b04118f04df [project @ 2007-01-19 03:21:16 by jwe]
jwe
parents: 6046
diff changeset
71 endif
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
72 endfunction