annotate scripts/image/ind2gray.m @ 1024:56520a75b5b3

[project @ 1995-01-11 20:30:04 by jwe]
author jwe
date Wed, 11 Jan 1995 20:30:04 +0000
parents b843a65fa977
children 611d403c7f3d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
1 # Copyright (C) 1995 John W. Eaton
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
2 #
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
3 # This file is part of Octave.
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
4 #
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
5 # Octave is free software; you can redistribute it and/or modify it
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
6 # under the terms of the GNU General Public License as published by the
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
7 # Free Software Foundation; either version 2, or (at your option) any
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
8 # later version.
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
9 #
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
10 # Octave is distributed in the hope that it will be useful, but WITHOUT
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
13 # for more details.
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
14 #
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
15 # You should have received a copy of the GNU General Public License
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
16 # along with Octave; see the file COPYING. If not, write to the Free
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
18
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
19 function Y = ind2gray (X, map)
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 559
diff changeset
20
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 559
diff changeset
21 # Convert an octave indexed image to a gray scale intensity image.
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
22 #
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
23 # Y = ind2gray (X) converts an indexed image to a gray scale intensity
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 559
diff changeset
24 # image. The current colormap is used to determine the intensities.
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 559
diff changeset
25 # The intensity values lie between 0 and 1 inclusive.
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
26 #
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
27 # Y = ind2gray (X, map) uses the specified colormap instead of the
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
28 # current one in the conversion process.
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
29 #
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 559
diff changeset
30 # SEE ALSO: gray2ind, rgb2ntsc, image, colormap
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
31
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
32 # Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994.
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
33
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
34 if (nargin < 1 || nargin > 2)
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
35 usage ("ind2gray (X, map)");
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
36 elseif (nargin == 1)
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
37 map = colormap ();
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
38 endif
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
39
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
40 # Convert colormap to intensity values.
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
41
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
42 yiq = rgb2ntsc (map);
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
43 y = yiq(:,1);
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
44
917
b843a65fa977 [project @ 1994-11-11 02:00:28 by jwe]
jwe
parents: 904
diff changeset
45 # We need Fortran indexing capability, but be sure to save the user's
b843a65fa977 [project @ 1994-11-11 02:00:28 by jwe]
jwe
parents: 904
diff changeset
46 # preference.
b843a65fa977 [project @ 1994-11-11 02:00:28 by jwe]
jwe
parents: 904
diff changeset
47
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
48 pref = do_fortran_indexing;
917
b843a65fa977 [project @ 1994-11-11 02:00:28 by jwe]
jwe
parents: 904
diff changeset
49
b843a65fa977 [project @ 1994-11-11 02:00:28 by jwe]
jwe
parents: 904
diff changeset
50 unwind_protect
b843a65fa977 [project @ 1994-11-11 02:00:28 by jwe]
jwe
parents: 904
diff changeset
51
b843a65fa977 [project @ 1994-11-11 02:00:28 by jwe]
jwe
parents: 904
diff changeset
52 do_fortran_indexing = "true";
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
53
917
b843a65fa977 [project @ 1994-11-11 02:00:28 by jwe]
jwe
parents: 904
diff changeset
54 # Replace indices in the input matrix with indexed values in the output
b843a65fa977 [project @ 1994-11-11 02:00:28 by jwe]
jwe
parents: 904
diff changeset
55 # matrix.
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
56
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
57 [rows, cols] = size (X);
917
b843a65fa977 [project @ 1994-11-11 02:00:28 by jwe]
jwe
parents: 904
diff changeset
58 Y = y(X(:));
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
59 Y = reshape (Y, rows, cols);
917
b843a65fa977 [project @ 1994-11-11 02:00:28 by jwe]
jwe
parents: 904
diff changeset
60
b843a65fa977 [project @ 1994-11-11 02:00:28 by jwe]
jwe
parents: 904
diff changeset
61 unwind_protect_cleanup
b843a65fa977 [project @ 1994-11-11 02:00:28 by jwe]
jwe
parents: 904
diff changeset
62 do_fortran_indexing = pref;
b843a65fa977 [project @ 1994-11-11 02:00:28 by jwe]
jwe
parents: 904
diff changeset
63 end_unwind_protect
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
64
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
65 endfunction