1 ## Copyright (C) 1994-2012 John W. Eaton
3 ## This file is part of Octave.
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.
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.
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/>.
20 ## @deftypefn {Function File} {} rgb2ntsc (@var{rgb})
21 ## Transform a colormap or image from RGB to NTSC.
25 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
29 function yiq = rgb2ntsc (rgb)
35 ## If we have an image convert it into a color map.
36 if (ismatrix (rgb) && ndims (rgb) == 3)
39 rgb = [rgb(:,:,1)(:), rgb(:,:,2)(:), rgb(:,:,3)(:)];
40 ## Convert to a double image.
43 low = double (intmin (C));
44 high = double (intmax (C));
45 rgb = (double (rgb) - low) / (high - low);
51 if (! ismatrix (rgb) || columns (rgb) != 3)
52 error ("rgb2ntsc: argument must be a matrix of size Nx3 or NxMx3");
56 trans = [ 0.299, 0.596, 0.211;
57 0.587, -0.274, -0.523;
58 0.114, -0.322, 0.312 ];
62 ## If input was an image, convert it back into one.
64 yiq = reshape (yiq, Sz);