1024
|
1 # Copyright (C) 1995 John W. Eaton |
|
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 the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # 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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
18 |
|
19 function Y = ind2gray (X, map) |
904
|
20 |
|
21 # Convert an octave indexed image to a gray scale intensity image. |
559
|
22 # |
1024
|
23 # Y = ind2gray (X) converts an indexed image to a gray scale intensity |
904
|
24 # image. The current colormap is used to determine the intensities. |
|
25 # The intensity values lie between 0 and 1 inclusive. |
559
|
26 # |
1024
|
27 # Y = ind2gray (X, map) uses the specified colormap instead of the |
|
28 # current one in the conversion process. |
559
|
29 # |
904
|
30 # SEE ALSO: gray2ind, rgb2ntsc, image, colormap |
559
|
31 |
1024
|
32 # Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994. |
|
33 |
|
34 if (nargin < 1 || nargin > 2) |
|
35 usage ("ind2gray (X, map)"); |
|
36 elseif (nargin == 1) |
|
37 map = colormap (); |
559
|
38 endif |
|
39 |
1024
|
40 # Convert colormap to intensity values. |
|
41 |
|
42 yiq = rgb2ntsc (map); |
559
|
43 y = yiq(:,1); |
|
44 |
917
|
45 # We need Fortran indexing capability, but be sure to save the user's |
|
46 # preference. |
|
47 |
559
|
48 pref = do_fortran_indexing; |
917
|
49 |
|
50 unwind_protect |
|
51 |
|
52 do_fortran_indexing = "true"; |
559
|
53 |
917
|
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 |