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 |
3381
|
20 ## -*- texinfo -*- |
3373
|
21 ## @deftypefn {Function File} {} ind2gray (@var{x}, @var{map}) |
|
22 ## Convert an Octave indexed image to a gray scale intensity image. |
|
23 ## If @var{map} is omitted, the current colormap is used to determine the |
|
24 ## intensities. |
|
25 ## @end deftypefn |
|
26 |
2311
|
27 ## SEE ALSO: gray2ind, rgb2ntsc, image, colormap |
904
|
28 |
3202
|
29 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
30 ## Created: July 1994 |
|
31 ## Adapted-By: jwe |
559
|
32 |
2312
|
33 function Y = ind2gray (X, map) |
1024
|
34 |
|
35 if (nargin < 1 || nargin > 2) |
|
36 usage ("ind2gray (X, map)"); |
|
37 elseif (nargin == 1) |
|
38 map = colormap (); |
559
|
39 endif |
|
40 |
2303
|
41 ## Convert colormap to intensity values. |
1024
|
42 |
|
43 yiq = rgb2ntsc (map); |
559
|
44 y = yiq(:,1); |
|
45 |
2303
|
46 ## We need Fortran indexing capability, but be sure to save the user's |
|
47 ## preference. |
917
|
48 |
559
|
49 pref = do_fortran_indexing; |
917
|
50 |
|
51 unwind_protect |
|
52 |
2360
|
53 do_fortran_indexing = 1; |
559
|
54 |
2303
|
55 ## Replace indices in the input matrix with indexed values in the output |
|
56 ## matrix. |
559
|
57 |
1024
|
58 [rows, cols] = size (X); |
917
|
59 Y = y(X(:)); |
1024
|
60 Y = reshape (Y, rows, cols); |
917
|
61 |
|
62 unwind_protect_cleanup |
|
63 do_fortran_indexing = pref; |
|
64 end_unwind_protect |
559
|
65 |
|
66 endfunction |