function rgb = ntsc2rgb(yiq)
%NTSC2RGB Convert NTSC values to RGB colorspace.
%	RGB = NTSC2RGB(YIQ) converts the N-by-3 NTSC (TV) values in the
%	matrix YIQ to RGB colorspace RGB.  If YIQ contains the NTSC 
%	luminance Y, which contains the gray scale information, and 
%	chrominance (I and Q) which contain the hue and saturation 
%	information, then RGB is N-by-3 and contains the red, green,
%	and blue values equivalent to those colors.
%
%	NTSC2RGB is useful for converting colormaps from NTSC space
%	to RGB space.
%
%	See also RGB2NTSC, RGB2IND, IND2RGB, IND2GRAY.

%	Clay M. Thompson 9-16-92
%	Copyright (c) 1993 by The MathWorks, Inc.
%	$Revision: 1.8 $  $Date: 1993/08/18 03:21:06 $

[m,n] = size(yiq);

if n~=3, error('YIQ must have 3 columns.'); end

T = [1.0 0.956 0.621; 1.0 -0.272 -0.647; 1.0 -1.106 1.703];

rgb = yiq*T';

% Make sure the rgb values are between 0.0 and 1.0
rgb = max(0,rgb);
d = find(any(rgb'>1));
rgb(d,:) = rgb(d,:)./(max(rgb(d,:)')'*ones(1,3));
