Mercurial > hg > octave-nkf
annotate scripts/image/ind2rgb.m @ 11191:01ddaedd6ad5
Reverse changeset b1f4bdc276b6. Use all lower case for "uniformoutput" option.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 04 Nov 2010 12:18:08 -0700 |
parents | be55736a0783 |
children | c776f063fefe |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2004, 2005, |
2 ## 2006, 2007 John W. Eaton | |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
1024 | 19 |
3381 | 20 ## -*- texinfo -*- |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
7017
diff
changeset
|
21 ## @deftypefn {Function File} {@var{rgb} =} ind2rgb (@var{x}, @var{map}) |
6247 | 22 ## @deftypefnx {Function File} {[@var{r}, @var{g}, @var{b}] =} ind2rgb (@var{x}, @var{map}) |
2311 | 23 ## Convert an indexed image to red, green, and blue color components. |
6247 | 24 ## If the colormap doesn't contain enough colors, pad it with the |
25 ## last color in the map. | |
3373 | 26 ## If @var{map} is omitted, the current colormap is used for the conversion. |
5642 | 27 ## @seealso{rgb2ind, image, imshow, ind2gray, gray2ind} |
3373 | 28 ## @end deftypefn |
904 | 29 |
3202 | 30 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312 | 31 ## Created: July 1994 |
32 ## Adapted-By: jwe | |
559 | 33 |
2312 | 34 function [R, G, B] = ind2rgb (X, map) |
1024 | 35 |
6247 | 36 ## Do we have the right number of inputs? |
1024 | 37 if (nargin < 1 || nargin > 2) |
6046 | 38 print_usage (); |
1024 | 39 elseif (nargin == 1) |
40 map = colormap (); | |
559 | 41 endif |
42 | |
6247 | 43 ## Check if X is an indexed image. |
44 if (ndims (X) != 2 || any (X(:) != round (X(:))) || min (X(:)) < 1) | |
45 error ("ind2rgb: first input argument must be an indexed image"); | |
46 endif | |
47 | |
48 ## Check the color map. | |
49 if (ndims (map) != 2 || columns (map) != 3) | |
50 error ("ind2rgb: second input argument must be a color map"); | |
51 endif | |
1024 | 52 |
6247 | 53 ## Do we have enough colors in the color map? |
54 maxidx = max (X(:)); | |
55 rm = rows (map); | |
56 if (rm < maxidx) | |
57 ## Pad with the last color in the map. | |
58 pad = repmat (map(end,:), maxidx-rm, 1); | |
59 map(end+1:maxidx, :) = pad; | |
60 endif | |
61 | |
62 ## Compute result | |
63 [hi, wi] = size (X); | |
3486 | 64 R = reshape (map (X(:), 1), hi, wi); |
65 G = reshape (map (X(:), 2), hi, wi); | |
66 B = reshape (map (X(:), 3), hi, wi); | |
559 | 67 |
6247 | 68 ## Use 3D array if only one output is requested. |
69 if (nargout <= 1) | |
70 R(:,:,3) = B; | |
71 R(:,:,2) = G; | |
72 endif | |
559 | 73 endfunction |