comparison scripts/image/rgb2ind.m @ 5922:1748af819fbb

[project @ 2006-08-14 18:16:57 by jwe]
author jwe
date Mon, 14 Aug 2006 18:16:57 +0000
parents 2618a0750ae6
children 045038e0108a
comparison
equal deleted inserted replaced
5921:28e8abe7027e 5922:1748af819fbb
16 ## along with Octave; see the file COPYING. If not, write to the Free 16 ## along with Octave; see the file COPYING. If not, write to the Free
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 ## 02110-1301, USA. 18 ## 02110-1301, USA.
19 19
20 ## -*- texinfo -*- 20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {[@var{x}, @var{map}] =} rgb2ind (@var{r}, @var{g}, @var{b}) 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})
22 ## Convert and RGB image to an Octave indexed image. 23 ## Convert and RGB image to an Octave indexed image.
23 ## @seealso{ind2rgb, rgb2ntsc} 24 ## @seealso{ind2rgb, rgb2ntsc}
24 ## @end deftypefn 25 ## @end deftypefn
25 26
26 ## Bugs: The color map may have duplicate entries. 27 ## Bugs: The color map may have duplicate entries.
29 ## Created: July 1994 30 ## Created: July 1994
30 ## Adapted-By: jwe 31 ## Adapted-By: jwe
31 32
32 function [X, map] = rgb2ind (R, G, B) 33 function [X, map] = rgb2ind (R, G, B)
33 34
34 if (nargin != 3) 35 if (nargin != 1 && nargin != 3)
35 usage ("[X, map] = rgb2ind (R, G, B)"); 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
36 endif 48 endif
37 49
38 if (size (R) != size (G) || size (R) != size (B)) 50 if (size (R) != size (G) || size (R) != size (B))
39 error ("rgb2ind: arguments must all have the same size"); 51 error ("rgb2ind: arguments must all have the same size");
40 endif 52 endif