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 |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
1024
|
19 |
3381
|
20 ## -*- texinfo -*- |
5922
|
21 ## @deftypefn {Function File} {[@var{x}, @var{map}] =} rgb2ind (@var{rgb}) |
|
22 ## @deftypefnx {Function File} {[@var{x}, @var{map}] =} rgb2ind (@var{r}, @var{g}, @var{b}) |
3373
|
23 ## Convert and RGB image to an Octave indexed image. |
5642
|
24 ## @seealso{ind2rgb, rgb2ntsc} |
3373
|
25 ## @end deftypefn |
|
26 |
2311
|
27 ## Bugs: The color map may have duplicate entries. |
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 [X, map] = rgb2ind (R, G, B) |
1024
|
34 |
5922
|
35 if (nargin != 1 && nargin != 3) |
|
36 print_usage (); |
|
37 endif |
|
38 |
|
39 if (nargin == 1) |
|
40 rgb = R; |
|
41 if (length (size (rgb)) == 3 && size (rgb, 3) == 3) |
|
42 R = rgb(:,:,1); |
|
43 G = rgb(:,:,2); |
|
44 B = rgb(:,:,3); |
|
45 else |
|
46 error ("rgb2ind: argument is not an RGB image"); |
|
47 endif |
559
|
48 endif |
|
49 |
1024
|
50 if (size (R) != size (G) || size (R) != size (B)) |
|
51 error ("rgb2ind: arguments must all have the same size"); |
|
52 endif |
559
|
53 |
1024
|
54 [hi, wi] = size (R); |
559
|
55 |
1024
|
56 X = zeros (hi, wi); |
|
57 |
|
58 map = zeros (hi*wi, 3); |
559
|
59 |
3486
|
60 map(:,1) = R(:); |
|
61 map(:,2) = G(:); |
|
62 map(:,3) = B(:); |
559
|
63 |
3486
|
64 X(:) = 1:(hi*wi); |
559
|
65 |
|
66 endfunction |