1 ## Copyright (C) 1994-2012 John W. Eaton
3 ## This file is part of Octave.
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 3 of the License, or (at
8 ## your option) any later version.
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.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {[@var{x}, @var{map}] =} rgb2ind (@var{rgb})
21 ## @deftypefnx {Function File} {[@var{x}, @var{map}] =} rgb2ind (@var{R}, @var{G}, @var{B})
22 ## Convert an RGB image to an Octave indexed image.
23 ## @seealso{ind2rgb, rgb2ntsc}
26 ## Bugs: The color map may have duplicate entries.
28 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
32 function [x, map] = rgb2ind (R, G, B)
34 if (nargin != 1 && nargin != 3)
40 if (length (size (rgb)) == 3 && size (rgb, 3) == 3)
45 error ("rgb2ind: argument is not an RGB image");
49 if (! size_equal (R, G) || ! size_equal (R, B))
50 error ("rgb2ind: arguments must all have the same size");
57 map = zeros (hi*wi, 3);