changelog shortlog tags changeset files revisions annotate raw

scripts/image/ntsc2rgb.m

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