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