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 |
5053
|
26 ## |
3457
|
27 ## @seealso{gray2ind, rgb2ntsc, image, and 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 |
3486
|
41 [rows, cols] = size (X); |
917
|
42 |
3486
|
43 ## Convert colormap to intensity values (the first column of the |
|
44 ## result of the call to rgb2ntsc) and then replace indices in |
|
45 ## the input matrix with indexed values in the output matrix (indexed |
|
46 ## values are the result of indexing the the intensity values by the |
|
47 ## elements of X(:)). |
559
|
48 |
3486
|
49 Y = reshape (((rgb2ntsc (map))(:,1))(X(:)), rows, cols); |
559
|
50 |
|
51 endfunction |