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 [X, map] = rgb2ind (R, G, B) |
904
|
20 |
|
21 # Convert and RGB image to an octave indexed image. |
559
|
22 # |
1024
|
23 # [X, map] = rgb2ind (R, G, B) |
559
|
24 # |
904
|
25 # SEE ALSO: ind2rgb, rgb2ntsc. |
559
|
26 # |
904
|
27 # Bugs: The color map may have duplicate entries. |
559
|
28 |
1024
|
29 # Written by Tony Richardson (amr@mpl.ucsd.edu) July 1994. |
|
30 |
|
31 if (nargin != 3) |
|
32 usage ("[X, map] = rgb2ind (R, G, B)"); |
559
|
33 endif |
|
34 |
1024
|
35 if (size (R) != size (G) || size (R) != size (B)) |
|
36 error ("rgb2ind: arguments must all have the same size"); |
|
37 endif |
559
|
38 |
1024
|
39 [hi, wi] = size (R); |
559
|
40 |
1024
|
41 X = zeros (hi, wi); |
|
42 |
|
43 map = zeros (hi*wi, 3); |
559
|
44 |
|
45 pref = do_fortran_indexing; |
917
|
46 |
|
47 unwind_protect |
|
48 |
|
49 do_fortran_indexing = "true"; |
559
|
50 |
917
|
51 map(:,1) = R(:); |
|
52 map(:,2) = G(:); |
|
53 map(:,3) = B(:); |
559
|
54 |
917
|
55 X(:) = 1:(hi*wi); |
559
|
56 |
917
|
57 unwind_protect_cleanup |
|
58 do_fortran_indexing = pref; |
|
59 end_unwind_protect |
559
|
60 |
|
61 endfunction |