Mercurial > hg > octave-nkf
annotate scripts/image/rgb2ind.m @ 14138:72c96de7a403 stable
maint: update copyright notices for 2012
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 02 Jan 2012 14:25:41 -0500 |
parents | c792872f8942 |
children | 1f911333ed3d |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
1 ## Copyright (C) 1994-2012 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
1024 | 18 |
3381 | 19 ## -*- texinfo -*- |
5922 | 20 ## @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
|
21 ## @deftypefnx {Function File} {[@var{x}, @var{map}] =} rgb2ind (@var{R}, @var{G}, @var{B}) |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
7017
diff
changeset
|
22 ## Convert an RGB image to an Octave indexed image. |
5642 | 23 ## @seealso{ind2rgb, rgb2ntsc} |
3373 | 24 ## @end deftypefn |
25 | |
2311 | 26 ## Bugs: The color map may have duplicate entries. |
904 | 27 |
3202 | 28 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312 | 29 ## Created: July 1994 |
30 ## Adapted-By: jwe | |
559 | 31 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
32 function [x, map] = rgb2ind (R, G, B) |
1024 | 33 |
5922 | 34 if (nargin != 1 && nargin != 3) |
35 print_usage (); | |
36 endif | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
37 |
5922 | 38 if (nargin == 1) |
39 rgb = R; | |
40 if (length (size (rgb)) == 3 && size (rgb, 3) == 3) | |
41 R = rgb(:,:,1); | |
42 G = rgb(:,:,2); | |
43 B = rgb(:,:,3); | |
44 else | |
45 error ("rgb2ind: argument is not an RGB image"); | |
46 endif | |
559 | 47 endif |
48 | |
6157 | 49 if (! size_equal (R, G) || ! size_equal (R, B)) |
1024 | 50 error ("rgb2ind: arguments must all have the same size"); |
51 endif | |
559 | 52 |
1024 | 53 [hi, wi] = size (R); |
559 | 54 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
55 x = zeros (hi, wi); |
1024 | 56 |
57 map = zeros (hi*wi, 3); | |
559 | 58 |
3486 | 59 map(:,1) = R(:); |
60 map(:,2) = G(:); | |
61 map(:,3) = B(:); | |
559 | 62 |
11469
c776f063fefe
Overhaul m-script files to use common variable name between code and documentation.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
63 x(:) = 1:(hi*wi); |
559 | 64 |
65 endfunction |