]> Creatis software - CreaPhase.git/blob - octave_packages/m/image/ntsc2rgb.m
update packages
[CreaPhase.git] / octave_packages / m / image / ntsc2rgb.m
1 ## Copyright (C) 1994-2012 John W. Eaton
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
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
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
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} ntsc2rgb (@var{yiq})
21 ## Transform a colormap or image from NTSC to RGB.
22 ## @seealso{rgb2ntsc}
23 ## @end deftypefn
24
25 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
26 ## Created: July 1994
27 ## Adapted-By: jwe
28
29 function rgb = ntsc2rgb (yiq)
30
31   if (nargin != 1)
32     print_usage ();
33   endif
34
35   ## If we have an image convert it into a color map.
36   if (ismatrix (yiq) && ndims (yiq) == 3)
37     is_image = true;
38     Sz = size (yiq);
39     yiq = [yiq(:,:,1)(:), yiq(:,:,2)(:), yiq(:,:,3)(:)];
40     ## Convert to a double image.
41     if (isinteger (yiq))
42       C = class (yiq);
43       low = double (intmin (C));
44       high = double (intmax (C));
45       yiq = (double (yiq) - low) / (high - low);
46     endif
47   else
48     is_image = false;
49   endif
50
51   if (! ismatrix (yiq) || columns (yiq) != 3)
52     error ("ntsc2rgb: argument must be a matrix of size Nx3 or NxMx3");
53   endif
54
55   ## Convert data
56   trans = [ 1.0,      1.0,      1.0;
57             0.95617, -0.27269, -1.10374;
58             0.62143, -0.64681, 1.70062 ];
59
60   rgb = yiq * trans;
61
62   ## If input was an image, convert it back into one.
63   if (is_image)
64     rgb = reshape (rgb, Sz);
65   endif
66
67 endfunction