changelog shortlog tags changeset files revisions annotate raw

scripts/image/rgb2ntsc.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} {} rgb2ntsc (@var{rgb})
22## Transform a colormap or image from RGB to NTSC.
23## @seealso{ntsc2rgb}
24## @end deftypefn
25
26## Author: Tony Richardson <arichard@stark.cc.oh.us>
27## Created: July 1994
28## Adapted-By: jwe
29
30function yiq = rgb2ntsc (rgb)
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 (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
57 trans = [ 0.299, 0.596, 0.211;
58 0.587, -0.274, -0.523;
59 0.114, -0.322, 0.312 ];
60
61 yiq = rgb * trans;
62
63 ## If input was an image, convert it back into one.
64 if (is_image)
65 yiq = reshape (yiq, Sz);
66 endif
67
68endfunction