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 octave indexed image to a gray scale intensity image. |
|
21 ## |
|
22 ## Y = ind2gray (X) converts an indexed image to a gray scale intensity |
|
23 ## image. The current colormap is used to determine the intensities. |
|
24 ## The intensity values lie between 0 and 1 inclusive. |
|
25 ## |
|
26 ## Y = ind2gray (X, map) uses the specified colormap instead of the |
|
27 ## current one in the conversion process. |
|
28 ## |
|
29 ## SEE ALSO: gray2ind, rgb2ntsc, image, colormap |
904
|
30 |
2312
|
31 ## Author: Tony Richardson <amr@mpl.ucsd.edu> |
|
32 ## Created: July 1994 |
|
33 ## Adapted-By: jwe |
559
|
34 |
2312
|
35 function Y = ind2gray (X, map) |
1024
|
36 |
|
37 if (nargin < 1 || nargin > 2) |
|
38 usage ("ind2gray (X, map)"); |
|
39 elseif (nargin == 1) |
|
40 map = colormap (); |
559
|
41 endif |
|
42 |
2303
|
43 ## Convert colormap to intensity values. |
1024
|
44 |
|
45 yiq = rgb2ntsc (map); |
559
|
46 y = yiq(:,1); |
|
47 |
2303
|
48 ## We need Fortran indexing capability, but be sure to save the user's |
|
49 ## preference. |
917
|
50 |
559
|
51 pref = do_fortran_indexing; |
917
|
52 |
|
53 unwind_protect |
|
54 |
2360
|
55 do_fortran_indexing = 1; |
559
|
56 |
2303
|
57 ## Replace indices in the input matrix with indexed values in the output |
|
58 ## matrix. |
559
|
59 |
1024
|
60 [rows, cols] = size (X); |
917
|
61 Y = y(X(:)); |
1024
|
62 Y = reshape (Y, rows, cols); |
917
|
63 |
|
64 unwind_protect_cleanup |
|
65 do_fortran_indexing = pref; |
|
66 end_unwind_protect |
559
|
67 |
|
68 endfunction |