convert_color
Outputs
which are mapped to avs parameters, inputs, and outputs, are for the
khoros library routine.
*******************************************************************************
Documentation for avs module vcltrans
Input
img input image of type xvimage
Type
output image colormap type.
type_flg if set the conversion is "type" otherwise
defalut is RGB.
norm normalization/scale factor.
norm_flg if set use "norm" else use 255.0.
trmatrix specifies a 3x3 user defined conversion
matrix.
mflg if set use trmatrix, else use "type" as the
conversion type.
OUTPUT
img overwrites the input image with new image
data and colormap type.
Description
vcltrans specifies the linear transformation matricies for
conversion between ntscYIQ, cieXYZ, ntscCMY, cieUVW and
ntscRGB or genericRGB colorspaces. These transformations
were taken from Pratt (Digital Image Processing, 1978). The
values in the matricies are based on NTSC RGB standard phos-
phers, as Pratt describes.
A user specified transformation matrix may also be used
(mflg must be set). The transformation matrix must be a 3x3
image of type FLOAT. The resulting color space model will be
GENERIC. The input image will still be normalized/scaled.
The input image can be any multi-spectral image.
The input image must be of type FLOAT, and of color space
model ntscYIQ, cieXYZ, ntscCMY, cieUVW, or ntscRGB or gener-
icRGB. The input image will be normalized by the variable
norm. The default is 255.
If converting from ntscYIQ, cieUVW, or cieXYZ to ntscCMY the
routine first converts to ntscRGB then converts to ntscCMY
because ntscCMY = 1 - ntscRGB.
If converting from ntscCMY to ntscYIQ, cieXYZ, or cieUVW the
routine first converts to ntscRGB then converts from ntscRGB
to ntscYIQ, cieXYZ or cieUVW using the transformation
matrices.
When converting between the different color spaces, care
must be taken in regards to the normalization factor. If the
image had been scaled by using vscale, then the scale factor
used in vscale should be the normalization factor used in
this routine. (Read the vcltrans(1) man page for detailed
description)
The output values of some of the transformations will be
negative, and some values will be greater than 1.
The following transformation matricies are used:
RGBtoYIQ = { { 0.299, 0.587, 0.114},
{ 0.596, -0.274, -0.322},
{ 0.211, -0.523, 0.312} };
RGBtoXYZ = { { 0.607, 0.174, 0.201},
{ 0.299, 0.587, 0.114},
{ 0.000, 0.066, 1.117} };
RGBtoUVW = { { 0.405, 0.116, 0.133},
{ 0.299, 0.587, 0.114},
{ 0.145, 0.827, 0.627} };
YIQtoRGB = { { 1.000, 0.956, 0.621},
{ 1.000, -0.272, -0.647},
{ 1.000, -1.106, 1.703} };
YIQtoXYZ = { { 0.967, 0.318, 0.594},
{ 1.000, 0.000, 0.000},
{ 1.173, -1.238, 1.870} };
YIQtoUVW = { { 0.653, 0.208, 0.403},
{ 1.000, 0.000, 0.000},
{ 1.599, -0.780, 0.623} };
XYZtoRGB = { { 1.910, -0.533, -0.288},
{-0.985, 2.000, -0.028},
{ 0.058, -0.118, 0.896} };
XYZtoYIQ = { { 0.000, 1.000, 0.000},
{ 1.407, -0.842, -0.451},
{ 0.932, 1.189, 0.233} };
XYZtoUVW = { { 0.667, 0.000, 0.000},
{ 0.000, 1.000, 0.000},
{-0.500, 1.500, 0.500} };
UVWtoRGB = { { 2.432, 0.332, -0.576},
{-1.519, 2.083, -0.057},
{ 1.440, -2.823, 1.803} };
UVWtoYIQ = { { 0.000, 1.000, 0.000},
{ 1.403, 0.534, -0.907},
{ 1.757, -1.898, 0.470} };
UVWtoXYZ = { { 1.500, 0.000, 0.000},
{ 0.000, 1.000, 0.000},
{ 1.500, -3.000, 2.000} };
These matricies can be found in the vcltrans.h include
file.
DIAGNOSTICS
The input image "img" is of type xvimage and must contain 3
data bands. If the mflg is set the input image can be any
multi-spectral image. If the mflg is not set the input image
must be of color space model ntscRGB, genericRGB, ntscYIQ,
ntscCMY, cieXYZ or cieUVW. The input image must be of data
type FLOAT.
Variable type specifes the output image color space type
(conversion). If flag type_flg is set the conversion is
"type" otherwise the default conversion is to ntscRGB.
The normalization/scale factor "norm" is used to normalize
the image between 0 and 1. If the flag "norm_flg" is set
use "norm" as the normalization/scale factor, else use
255.0.
The image "trmatrix" specifies a 3x3 user defined conversion
matrix. The image must contain only one data band, have a
data storage type of FLOAT, and have map enable set to
OPTIONAL. If the mflg is set, use trmatrix as the transfor-
mation matrix, else use "type" as the conversion type.
The input image is used as the output image "img", so one
must be careful not to overwrite important input image data.
vcltrans returns a 1 upon success and a 0 upon failure.
See also
vcltrans(1), intro(3), vipl(3), verror(3), vutils(3)
RESTRICTIONS
The input image must be of one of the color space models
listed above. The data type of the input must be
VFF_TYP_FLOAT.
Author
Donna Koechner, Tom Sauer
COPYRIGHT
Copyright 1991, University of New Mexico. All rights
reserved.
*******************************************************************************
Documentation for avs module vcluv
INPUT
img1 input multispectral image of color space
model ntscRGB, ntscYIQ, ntscCMY, genericRGB,
cieXYZ, cieUVW or GENERIC.
norm normalization factor
OUTPUT
img1 converted image of type FLOAT normalized
between 0 and 1.
DESCRIPTION
vcluv converts ntsc RGB,generic RGB ntsc YIQ, ntsc CMY, cie
XYZ, cie UVW or GENERIC color spaces to cieucs Luv color
spaces. Color images are displayed and manipulated using
the NTSC receiver primary color system; thus reference white
is set to R = 1, B = 1, G = 1.
The algorithm used is as follows:
L = 25(Y/Y0)^1/3 - 16
u = 13L(u' - u0')
u = 13L(v' - v0')
where u', v', u0' and v0' are
u' = 4X / X + 15Y + 3Z
v' = 9Y / X + 15Y + 3Z
u0' = 4X0 / X + 15Y + 3Z
u0' = 9Y0 / X + 15Y + 3Z
X0, Y0 and Z0 are calculated by setting R = 1, G = 1, B = 1
and converting to the XYZ color space (see vcltrans).
This routine needs to work with an image normalized between
0 and 1.
This algorithm was taken from Fundamentals of Digital Image
Processing, Jain, and Color Science: Concepts and Methods,
Quantitative Data and Formulae, Wyszecki and Stiles.
The norm option specifies the normalization factor. There
is no default for the norm value.
This routine will not touch the data map; therefore, the map
may be invalid after running this routine. The map may be
deleted from the image or a new map may be inserted.
Variable img1 is the input multispectral image of colormap
model RGB or HSV of data type FLOAT.
The variable norm is a normalization factor since the data
must be normalized between zero and one.
vcluv will return a one upon success and a zero upon
failure.
SEE ALSO
vcluv(1), intro(3), vipl(3), verror(3), vutils(3)
RESTRICTIONS
vcluv must have an input image of data storage type FLOAT
and the input image color map model must be of type ntscRGB,
genericRGB, cieXYZ, cieUVW, ntscYIQ, ntscCMY, or GENERIC.
AUTHOR
Tom Sauer
COPYRIGHT
Copyright 1991, University of New Mexico. All rights
reserved.
*******************************************************************************
Documentation for avs module vcmtrans
INPUT
OUTPUT
DESCRIPTION
Takes a multi-spectral input image and output an image of color
space model GENERIC by applying a user specified
color space conversion matrix.
The input image must be of data storage type FLOAT, and
contain three data bands. The color space model for the
input image can be set to any type.
The input image will be normalized by the value specified by
the -n option. The default is 255.
The second input image specifies the transformation matrix.
This image must be of data storage type float and must be
a 3x3 image. The format of this image must be:
{ 11, 12, 13 }
{ 21, 22, 23 }
{ 31, 32, 33 }
This image can be created using vcustom. It is important to
remember that the input image will be normalized by the
normalization option. The default is 255.0. The conversion
is performed as follows:
Band 1 of the input image is updated by:
pixel = matrix[0][0]*(t1) + matrix[0][1]*(t2) + matrix[0][2]*(t3)
Band 2 of the input image is updated by:
pixel = matrix[1][0]*(t1) + matrix[1][1]*(t2) + matrix[1][2]*(t3)
Band 3 of the input image is updated by:
pixel = matrix[2][0]*(t1) + matrix[2][1]*(t2) + matrix[2][2]*(t3)
where t1 = pixel from band 1
where t2 = pixel from band 2
where t3 = pixel from band 3
When converting between the different color spaces,
care must be taken in regards to the normalization
factor. If the image had been scaled by using
vscale, then the scale factor used in vscale
should be the normalization factor used in this
routine. The resulting image should not be normalized by using vnormal,
if the inverse transformation is desired. The data will be corrupted.
NOTE: The output values of some of the transformations will be negative, and
some values will be greater than 1. If conversion to BYTE is desired, then
a possible solution is:
Use vbandspt3 to obtain 3 grey level images.
Use voffset to offset the image by the maximum negative value.
The offset value will most likely be different for each of
the three images.
Use vstats to get the maximum pixel value in the image and
divide that by the maximum desired pixel value. This gives the
scale factor. (EX. 3.2/255 = scale factor).
Now use vconvert to scale (NOT NORMALIZE) by the computed
scale factor and convert to BYTE.
vbandcomb can be used to create a multi-spectral image.
SEE ALSO
intro(1), verror(3), vgparms(3), vutils(3)
RESTRICTIONS
The input image must be of data storage type FLOAT.
The user specified matrix image must have a data
storage type for float.
COPYRIGHT
Copyright 1991, University of New Mexico. All rights reserved.
*******************************************************************************
Documentation for avs module vcrgbhls
INPUT
img1 input multispectral image of colormap model
RGB or HLS.
type 1 = conversion RGB to HLS
0 = conversion HLS to RGB
type_flg if set, use the conversion specified by type
norm normalization factor
norm_flg normalization flag. If set, use norm as the
normalization factor otherwise, default nor-
malization is set to 255.
OUTPUT
img1 converted image of type FLOAT normalized
between 0 and 1.
DESCRIPTION
vcrgbhls converts from a multispectral image of color space
model RGB to HLS and vice versa. The RGB image is assumed
to be of type NTSC or generic. Generic RGB is an image that
is RGB but can not legally be classified as NTSC. This rou-
tine needs to work with an image normalized between 0 and 1.
If norm_flg is set, then use the value norm to normalize the
input image. Otherwise, default normalization value is 255.
The routine sets the zero degree hue to be red, with green
and blue following in counter clockwise direction. When
converting from RGB to HLS, any time that the saturation is
0 (grey level), hue is undefined and is therefore set to 0
(red). This may degrade the image. When converting from
HLS to RGB, any time a saturation of zero is encountered,
the R,G, and B data are all assigned the value of L (result
is a gray level).
The algorithm which transforms from RGB to HLS was taken
from Foley & VanDam (Fundamentals of Interactive Computer
Graphics), and the HLS to RGB was taken from Ken Fishkin
(with our modifications).
This routine will not touch the data map; therefor, the data
map may be invalid after performing the converstion.
DIAGNOSTICS
Variable img1 is the input multispectral image of colormap
model RGB or HLS of data type FLOAT.
Variable type is used for conversion from RGB to HLS. If
type = 1, conversion is from RGB to HLS. If type = 0,
conversion is from HLS to RGB. If variable type_flg is set,
use the conversion specified by type.
The variable norm is a normalization factor since the data
must be normalized between zero and one. If variable
norm_flg is set, use the normalization factor specified by
norm. Otherwise, use the default normalization factor of
255.
Variable img1 is used as the input image and the output
image. Care must be taken not to overwrite important image
data.
vcrgbhls returns a 1 upon success and a 0 upon failure.
SEE ALSO
vcrgbhls(1), intro(3), vipl(3), verror(3), vutils(3)
RESTRICTIONS
vcrgbhls must have an input image of data type FLOAT and
the input image color map model must be of type RGB or HLS.
AUTHOR
Donna Koechner, Tom Sauer
COPYRIGHT
Copyright 1991, University of New Mexico. All rights
reserved.
*******************************************************************************
Documentation for avs module vcrgbhsv
INPUT
img1 input multispectral image of colormap model
RGB or HSV.
type 1 = conversion RGB to HSV
0 = conversion HSV to RGB
type_flag if set, use the conversion specified by type
norm normalization factor
norm_flag normalization flag. If set, use norm as the
normalization factor otherwise, default nor-
malization is set to 255
OUTPUT
img1 converted image of type FLOAT normalized
between 0 and 1.
DESCRIPTION
vcrgbhls converts from a multispectral image of color space
model RGB to HSV and vice versa. The RGB image is assumed
to be of type NTSC or generic. Generic RGB is an image that
is RGB but can not legally be classified as NTSC. This rou-
tine needs to work with an image normalized between 0 and 1.
If norm_flg is set, then use the value norm to normalize the
input image. Otherwise, default normalization value is 255.
The routine sets the zero degree hue to be red, with green
and blue following in counter clockwise direction. When
converting from RGB to HSV, any time that the saturation is
0 (grey level), hue is undefined and is therefore set to 0
(red). This may degrade the image. When converting from
HSV to RGB, any time a saturation of zero is encountered,
the R,G, and B data are all assigned the value of V (result
is a gray level).
The algorithm which transforms from RGB to HSV and HSV to
RGB was taken from Foley & VanDam (Fundamentals of
Interactive Computer Graphics), (with our modifications).
This routine will not touch the data map; therefore, the
data map may be invalid after performing the conversion.
DIAGNOSTICS
Variable img1 is the input multispectral image of colormap
model RGB or HSV of data type FLOAT.
Variable type is used for conversion from RGB to HSV. If
type = 1, conversion is from RGB to HSV. If type = 0,
conversion is from HSV to RGB. If variable type_flg is set,
use the conversion specified by type.
The variable norm is a normalization factor since the data
must be normalized between zero and one. If variable
norm_flg is set, use the normalization factor specified by
norm. Otherwise, use the default normalization factor of
255.
Variable img1 is used as the input image and the output
image. Care must be taken not to overwrite important image
data.
vcrgbhls returns a 1 upon success and a 0 upon failure.
SEE ALSO
vcrgbhsv(1), intro(3), vipl(3), verror(3), vutils(3)
RESTRICTIONS
vcrgbhsv must have an input image of data storage type FLOAT
and the input image color map model must be of type gener-
icRGB, ntscRGB or HSV.
AUTHOR
Tom Sauer
COPYRIGHT
Copyright 1991, University of New Mexico. All rights
reserved.
*******************************************************************************
Documentation for avs module vgamut
INPUT
image pointer to xvimage structure to be processed
ncolors number of colors allowed in the output image
bits number of bits of precision for the color
prequantization
fraction allocation ratio of color split methods. 0.0
is population, 1.0 is subspace 2-norm.
OUTPUT
image holds the result of the operation. The out-
put data type is the same as the input data
type.
Return Value: 1 on success, 0 on failure.
DESCRIPTION
vgamut takes a 3 band multi-spectral image, where each band
would normally represent one component of a 24-bit RGB
image, and generates a pseudo color image with a specified
number of colors that can be displayed using editimage or
putimage. The object is to make the displayable image look
like the true 24-bit RGB image even though the number of
colors is greatly restricted.
The color compression is performed by isolating clusters of
"neighboring" colors in a three dimensional histogram, with
each axis being one of the color components. The clusters
are obtained using a modified version of Heckberts median
cut. The true colors are then matched to the closest clus-
ter, and the input RGB triplet is then re-mapped to an n-
color pseudo color image.
To keep the histogram from becoming exceedingly large (max
of around 2^24 bytes), one may need to quantize the grey
levels of the input bands to less than 8 bits. 6 bits (64
levels) gives results that are reasonable in a short amount
of time. The number of bits that are kept is called the
color precision, which can be specified at execution time.
The general tradeoff is that smaller precision is faster
and takes less memory, but it looks worse too. High preci-
sion takes longer and great gobs of memory, but looks good,
provided that a reasonable number (say 128) colors is speci-
fied. The execution time is very dependent on the image
statistics. In general, a small number of colors is faster
than a large number of colors. In either case, if the image
has good spatial color coherence, execution time is greatly
reduced.
The allocation fraction (-r) controls how large areas of
nearly the same color are handled. An allocation fraction of
0.0 will cause the large areas to be broken into as many
colors as possible with the largest areas of a particular
color range being broken first. An allocation fraction of
1.0 will attempt to preserve the detail in the image be
preserving the color range of all parts of the image at the
expense of smooth coloring of the larger areas. An alloca-
tion fraction of around 0.2 to 0.5 gives very good results
on most images.
As a special note, be sure that the input image has a map
that has one-to-one correspondence to the pixel values (i.e.
the pixel value is the grey level). If this is not the case,
use vmapdata(1) to convert to a linear map.
Note that image is used for both the input xvimage structure
and the resulting output xvimage structure. This is done to
save space, but you must be careful not to overwrite impor-
tant data.
If the input image contains less than the number of colors
requested then the output image will contain only the number
of colors present in the input image. A diagnostic messsage
will printed to STDERR when this occurs, provided that the
KHOROS_VERBOSE environment variable is set.
No dithering is done by vgamut. Dithering in color space
can often cause the image to look very noisy due to the
color sensitivity of the eye. The result images from vgamut
may display some banding effects, but these are often more
tolerable visually than the noise that would result from a
color dithering process.
If the KHOROS_VERBOSE environment variable is set then an
additional diagnostic message, the number of colors actually
found in the image, will be printed. The color count is sub-
ject to the color precision specified by the -p option.
SEE ALSO
vgamut(1), intro(3), vipl(3), verror(3), vutils(3) lvmap-
data(1)
RESTRICTIONS
vgamut works only on BYTE imagesk with three bands of data.
AUTHOR
Scott Wilson
COPYRIGHT
Copyright 1991, University of New Mexico. All rights
reserved.
*******************************************************************************