annotate scripts/image/rgb2ind.m @ 18075:24759ac2b8cb stable

doc: Periodic spellcheck of documentation * aspell-octave.en.pws: Remove WebKit from private dictionary. * external.txi: Fix typos and use two spaces for sentence breaks. * install.txi: Use @nospell macro around gl2ps. * rgb2ind.m: Correct British spelling of colour to American spelling.
author Rik <rik@octave.org>
date Wed, 04 Dec 2013 08:41:22 -0800
parents b8cd17571a1d
children 4197fc428c7d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17744
d63878346099 maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents: 17395
diff changeset
1 ## Copyright (C) 1994-2013 John W. Eaton
15687
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
2 ## Copyright (C) 2012 Carnë Draug
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
3 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
4 ## This file is part of Octave.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
5 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6157
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6157
diff changeset
9 ## your option) any later version.
2313
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
10 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
14 ## General Public License for more details.
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
15 ##
5ca126254d15 [project @ 1996-07-11 21:25:22 by jwe]
jwe
parents: 2312
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6157
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6157
diff changeset
18 ## <http://www.gnu.org/licenses/>.
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
19
3381
69b167451491 [project @ 1999-12-15 20:48:10 by jwe]
jwe
parents: 3373
diff changeset
20 ## -*- texinfo -*-
5922
1748af819fbb [project @ 2006-08-14 18:16:57 by jwe]
jwe
parents: 5642
diff changeset
21 ## @deftypefn {Function File} {[@var{x}, @var{map}] =} rgb2ind (@var{rgb})
11469
c776f063fefe Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents: 8920
diff changeset
22 ## @deftypefnx {Function File} {[@var{x}, @var{map}] =} rgb2ind (@var{R}, @var{G}, @var{B})
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15693
diff changeset
23 ## Convert an image in red-green-blue (RGB) color space to an indexed image.
16630
5d6243c2acbf rgb2ind.m: Enable handling of ND images, and enable n,tol,map,dither as inputs.
Adam H Aitkenhead <adamhaitkenhead@gmail.com>
parents: 15715
diff changeset
24 ##
17992
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
25 ## The input image @var{rgb} can be specified as a single matrix of size
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
26 ## @nospell{MxNx3}, or as three separate variables, @var{R}, @var{G}, and
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
27 ## @var{B}, its three colour channels, red, green, and blue.
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
28 ##
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
29 ## It outputs an indexed image @var{x} and a colormap @var{map} to interpret
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
30 ## an image exactly the same as the input. No dithering or other form of color
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
31 ## quantization is performed. The output class of the indexed image @var{x}
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
32 ## can be uint8, uint16 or double, whichever is required to specify the
18075
24759ac2b8cb doc: Periodic spellcheck of documentation
Rik <rik@octave.org>
parents: 17992
diff changeset
33 ## number of unique colors in the image (which will be equal to the number
17992
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
34 ## of rows in @var{map}) in order
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
35 ##
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
36 ## Multi-dimensional indexed images (of size @nospell{MxNx3xK}) are also
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
37 ## supported, both via a single input (@var{rgb}) or its three colour channels
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
38 ## as separate variables.
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
39 ##
14260
1f911333ed3d doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
40 ## @seealso{ind2rgb, rgb2hsv, rgb2ntsc}
3373
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3202
diff changeset
41 ## @end deftypefn
36405da8e173 [project @ 1999-11-23 20:54:17 by jwe]
jwe
parents: 3202
diff changeset
42
17990
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
43 ## FIXME: This function has a very different syntax than the Matlab
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
44 ## one of the same name.
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
45 ## Octave function does not support N, MAP, DITHER, or TOL arguments.
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
46
3202
44d82b369c78 [project @ 1998-10-29 20:27:57 by jwe]
jwe
parents: 2847
diff changeset
47 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
2312
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
48 ## Created: July 1994
204cc7db6f4a [project @ 1996-07-11 21:20:36 by jwe]
jwe
parents: 2311
diff changeset
49 ## Adapted-By: jwe
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
50
17990
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
51 function [x, map] = rgb2ind (R, G, B)
1024
56520a75b5b3 [project @ 1995-01-11 20:30:04 by jwe]
jwe
parents: 917
diff changeset
52
17990
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
53 if (nargin != 1 && nargin != 3)
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
54 print_usage ();
5922
1748af819fbb [project @ 2006-08-14 18:16:57 by jwe]
jwe
parents: 5642
diff changeset
55 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
56
17990
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
57 if (nargin == 1)
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
58 rgb = R;
17992
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
59 if (ndims (rgb) > 4 || size (rgb, 3) != 3)
17990
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
60 error ("rgb2ind: argument is not an RGB image");
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
61 else
17992
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
62 R = rgb(:,:,1,:);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
63 G = rgb(:,:,2,:);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
64 B = rgb(:,:,3,:);
17990
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
65 endif
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
66 elseif (! size_equal (R, G, B))
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
67 error ("rgb2ind: R, G, and B must have the same size");
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
68 endif
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
69
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
70 x = reshape (1:numel (R), size (R));
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
71
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
72 map = unique ([R(:) G(:) B(:)], "rows");
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
73 [~, x] = ismember ([R(:) G(:) B(:)], map, "rows");
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
74 x = reshape (x, size (R));
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
75
15687
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
76 ## a colormap is of class double and values between 0 and 1
17990
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
77 switch (class (R))
15687
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
78 case {"single", "double", "logical"}
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
79 ## do nothing, return the same
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
80 case {"uint8", "uint16"}
17990
a40156e8b6a7 rgb2ind: backout 5d6243c2acbf removing all quantization (bug #40669)
Carnë Draug <carandraug@octave.org>
parents: 17744
diff changeset
81 map = double (map) / double (intmax (class (R)));
15687
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
82 case "int16"
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
83 map = (double (im) + 32768) / 65535;
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
84 otherwise
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
85 error ("unsupported image class %s", im_class);
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
86 endswitch
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
87
15687
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
88 ## we convert to the smallest class necessary to encode the image. Matlab
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
89 ## documentation does not mention what it does when uint16 is not enough...
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
90 ## When an indexed image is of integer class, there's a -1 offset to the
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
91 ## colormap, hence the adjustment
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
92 if (rows (map) < 256)
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
93 x = uint8 (x - 1);
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
94 elseif (rows (map) < 65536)
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
95 x = uint16 (x - 1);
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
96 else
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
97 ## leave it as double
89c8d8f8f87b rgb2ind: find unique RGB values for indexed image and scale colormap for correct range
Carnë Draug <carandraug+dev@gmail.com>
parents: 14260
diff changeset
98 endif
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15693
diff changeset
99
559
4e826edfbc56 [project @ 1994-07-25 22:18:28 by jwe]
jwe
parents:
diff changeset
100 endfunction
15683
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
101
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
102 %% Test input validation
806ea52af230 Overhaul m-files in image directory to provide better support for images stored as integers.
Rik <rik@octave.org>
parents: 14260
diff changeset
103 %!error rgb2ind ()
16713
ab5d0b358b94 rgb2ind.m: fix input validation tests
Mike Miller <mtmiller@ieee.org>
parents: 16633
diff changeset
104 %!error rgb2ind (1,2,3,4,5,6,7)
17992
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
105 %!error <RGB> rgb2ind (rand (10, 10, 4))
15714
b1cd65881592 Clean up scripts in image directory.
Rik <rik@octave.org>
parents: 15693
diff changeset
106
17992
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
107 ## FIXME: the following tests simply make sure that rgb2ind and ind2rgb
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
108 ## reverse each other. We should have better tests for this.
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
109
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
110 ## Typical usage
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
111 %!test
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
112 %! rgb = rand (10, 10, 3);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
113 %! [ind, map] = rgb2ind (rgb);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
114 %! assert (ind2rgb (ind, map), rgb);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
115 %!
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
116 %! ## test specifying the RGB channels separated
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
117 %! [ind, map] = rgb2ind (rgb(:,:,1), rgb(:,:,2), rgb(:,:,3));
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
118 %! assert (ind2rgb (ind, map), rgb);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
119
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
120 ## Test N-dimensional images
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
121 %!test
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
122 %! rgb = rand (10, 10, 3, 10);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
123 %! [ind, map] = rgb2ind (rgb);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
124 %! assert (ind2rgb (ind, map), rgb);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
125 %! [ind, map] = rgb2ind (rgb(:,:,1,:), rgb(:,:,2,:), rgb(:,:,3,:));
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
126 %! assert (ind2rgb (ind, map), rgb);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
127
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
128 ## Test output class
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
129 %!test
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
130 %! ## this should have more than 65536 unique colors
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
131 %! rgb = rand (1000, 1000, 3);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
132 %! [ind, map] = rgb2ind (rgb);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
133 %! assert (class (ind), "double");
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
134 %! assert (class (map), "double");
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
135 %!
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
136 %! ## and this should have between 255 and 65536 unique colors
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
137 %! rgb = rand (20, 20, 3);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
138 %! [ind, map] = rgb2ind (rgb);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
139 %! assert (class (ind), "uint16");
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
140 %! assert (class (map), "double");
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
141 %!
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
142 %! ## and this certainly less than 256 unique colors
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
143 %! rgb = rand (10, 10, 3);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
144 %! [ind, map] = rgb2ind (rgb);
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
145 %! assert (class (ind), "uint8");
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
146 %! assert (class (map), "double");
b8cd17571a1d rgb2ind: support for N-dimensional images (bug #40664)
Carnë Draug <carandraug@octave.org>
parents: 17990
diff changeset
147