8920
|
1 ## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2005, 2006, 2007, 2008 |
7017
|
2 ## John W. Eaton |
2313
|
3 ## |
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
|
7 ## under the terms of the GNU General Public License as published by |
7016
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
2313
|
10 ## |
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
559
|
19 |
3381
|
20 ## -*- texinfo -*- |
3373
|
21 ## @deftypefn {Function File} {} rgb2ntsc (@var{rgb}) |
7375
|
22 ## Transform a colormap or image from RGB to NTSC. |
|
23 ## @seealso{ntsc2rgb} |
3373
|
24 ## @end deftypefn |
1024
|
25 |
3202
|
26 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
27 ## Created: July 1994 |
|
28 ## Adapted-By: jwe |
1024
|
29 |
2312
|
30 function yiq = rgb2ntsc (rgb) |
1024
|
31 |
|
32 if (nargin != 1) |
6046
|
33 print_usage (); |
1024
|
34 endif |
|
35 |
7375
|
36 ## If we have an image convert it into a color map. |
|
37 if (ismatrix (rgb) && ndims (rgb) == 3) |
|
38 is_image = true; |
|
39 Sz = size (rgb); |
|
40 rgb = [rgb(:,:,1)(:), rgb(:,:,2)(:), rgb(:,:,3)(:)]; |
|
41 ## Convert to a double image. |
|
42 if (isinteger (rgb)) |
|
43 C = class (rgb); |
|
44 low = double (intmin (C)); |
|
45 high = double (intmax (C)); |
|
46 rgb = (double (rgb) - low) / (high - low); |
|
47 endif |
|
48 else |
|
49 is_image = false; |
|
50 endif |
|
51 |
|
52 if (! ismatrix (rgb) || columns (rgb) != 3) |
|
53 error ("rgb2ntsc: argument must be a matrix of size Nx3 or NxMx3"); |
|
54 endif |
|
55 |
|
56 ## Convert data |
1024
|
57 trans = [ 0.299, 0.596, 0.211; |
|
58 0.587, -0.274, -0.523; |
|
59 0.114, -0.322, 0.312 ]; |
|
60 |
559
|
61 yiq = rgb * trans; |
|
62 |
7375
|
63 ## If input was an image, convert it back into one. |
|
64 if (is_image) |
|
65 yiq = reshape (yiq, Sz); |
|
66 endif |
|
67 |
559
|
68 endfunction |