2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
1024
|
19 |
2311
|
20 ## Convert an indexed image to red, green, and blue color components. |
|
21 ## |
|
22 ## [R G B] = ind2rgb(X) uses the current colormap for the conversion. |
|
23 ## |
|
24 ## [R G B] = ind2rgb(X,map) uses the specified colormap. |
|
25 ## |
|
26 ## SEE ALSO: rgb2ind, image, imshow, ind2gray, gray2ind. |
904
|
27 |
3202
|
28 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
29 ## Created: July 1994 |
|
30 ## Adapted-By: jwe |
559
|
31 |
2312
|
32 function [R, G, B] = ind2rgb (X, map) |
1024
|
33 |
|
34 if (nargin < 1 || nargin > 2) |
|
35 usage ("ind2rgb (X, map)"); |
|
36 elseif (nargin == 1) |
|
37 map = colormap (); |
559
|
38 endif |
|
39 |
1024
|
40 [hi, wi] = size (X); |
|
41 |
2303
|
42 ## XXX FIXME XXX -- we should check size of X and map. |
559
|
43 |
|
44 pref = do_fortran_indexing; |
|
45 |
917
|
46 unwind_protect |
|
47 |
2360
|
48 do_fortran_indexing = 1; |
559
|
49 |
1024
|
50 R = map (X(:), 1); |
|
51 G = map (X(:), 2); |
|
52 B = map (X(:), 3); |
559
|
53 |
1024
|
54 R = reshape (R, hi, wi); |
|
55 G = reshape (G, hi, wi); |
|
56 B = reshape (B, hi, wi); |
917
|
57 |
|
58 unwind_protect_cleanup |
|
59 do_fortran_indexing = pref; |
|
60 end_unwind_protect |
559
|
61 |
|
62 endfunction |