Create series of slices through different color spaces. Usage: example_palette luv
, generates luv_*.gif
(44 images)
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vigra/multi_array.hxx>
#include <vigra/stdimagefunctions.hxx>
#include <vigra/colorconversions.hxx>
template<class Polar2Cartesian, class Cartesian2RGB, class RGB2RGBPrime>
Polar2Cartesian polar2Cartesian, Cartesian2RGB cartesian2RGB, RGB2RGBPrime rgb2RGBPrime)
{
int w = result.width();
int h = result.height();
for(int y=0; y<h; ++y)
{
for(int x=0; x<w; ++x)
{
double saturation = (float)x / (w-1);
double color = (float)y / (h-1) * 360.0;
polar2Cartesian(color, brightness, saturation));
if(saturation > 1.0 ||
rgb.
red() < 0.0 || rgb.
red() > 255.0 ||
{
}
else
{
result(x,y) = rgb2RGBPrime(rgb);
}
}
}
}
template<class Polar2Cartesian, class Cartesian2RGB, class RGB2RGBPrime>
Polar2Cartesian polar2Cartesian, Cartesian2RGB cartesian2RGB, RGB2RGBPrime rgb2RGBPrime)
{
int w = result.width();
int h = result.height();
for(int y=0; y<h; ++y)
{
for(int x=0; x<w; ++x)
{
double brightness = (float)x / (w-1);
double color = (float)y / (h-1) * 360.0;
polar2Cartesian(color, brightness, saturation));
if(saturation > 1.0 ||
rgb.
red() < 0.0 || rgb.
red() > 255.0 ||
{
}
else
{
result(x,y) = rgb2RGBPrime(rgb);
}
}
}
}
template<class Polar2Cartesian, class Cartesian2RGB, class RGB2RGBPrime>
Polar2Cartesian polar2Cartesian, Cartesian2RGB cartesian2RGB, RGB2RGBPrime rgb2RGBPrime)
{
int w = result.width();
int h = result.height();
for(int y=0; y<h; ++y)
{
for(int x=0; x<w; ++x)
{
double brightness = (float)x / (w-1);
double saturation = (float)y / (h-1);
polar2Cartesian(color, brightness, saturation));
if(saturation > 1.0 ||
rgb.
red() < 0.0 || rgb.
red() > 255.0 ||
{
}
else
{
result(x,y) = rgb2RGBPrime(rgb);
}
}
}
}
template<class Polar2Cartesian, class Cartesian2RGB, class RGB2RGBPrime>
Polar2Cartesian polar2Cartesian, Cartesian2RGB cartesian2RGB, RGB2RGBPrime rgb2RGBPrime)
{
int w = result.width();
int h = result.height();
for(int y=0; y<h; ++y)
{
for(int x=0; x<w; ++x)
{
double dx = x/128.0 - 1.0;
double dy = -y/128.0 + 1.0;
double color = 180.0/M_PI*std::atan2(dy,dx);
double saturation = std::sqrt(dx*dx+dy*dy);
polar2Cartesian(color, brightness, saturation));
if(saturation > 1.0 ||
rgb.
red() < 0.0 || rgb.
red() > 255.0 ||
{
}
else
{
result(x,y) = rgb2RGBPrime(rgb);
}
}
}
}
{
char buf[1000];
if(i < 10)
sprintf(buf, "%s_%s_0%d.gif", colorspace, diagram, i);
else
sprintf(buf, "%s_%s_%d.gif", colorspace, diagram, i);
std::cout << "Wrote " << buf << std::endl;
}
template<class Polar2Cartesian, class Cartesian2RGB, class RGB2RGBPrime>
void createColorSpaceSlices(char const * colorspace,
Polar2Cartesian polar2Cartesian, Cartesian2RGB cartesian2RGB, RGB2RGBPrime rgb2RGBPrime)
{
int w = 257;
int h = 257;
int Ymax = 10;
for(int i=0; i<=Ymax; ++i)
{
createColorVsSaturation(result, (float)i/Ymax,
polar2Cartesian, cartesian2RGB, rgb2RGBPrime);
write(colorspace, "ColorVsSaturation", i, result);
createColorVsBrightness(result, (float)i/Ymax,
polar2Cartesian, cartesian2RGB, rgb2RGBPrime);
write(colorspace, "ColorVsBrightness", i, result);
createSaturationVsBrightness(result, (float)i/Ymax*360.0,
polar2Cartesian, cartesian2RGB, rgb2RGBPrime);
write(colorspace, "SaturationVsBrightness", i, result);
createColorCircle(result, (float)i/Ymax,
polar2Cartesian, cartesian2RGB, rgb2RGBPrime);
write(colorspace, "ColorCircle", i, result);
}
}
void usage(char const * prog)
{
std::cerr << "Usage: " << prog << " colorspace\n"
"with colorspace in [lab luv ypbpr ycbcr yiq yuv]\n\n";
std::cerr << "This programm calculates slices through the given color space\n"
"Images are named 'lab_SaturationVsBrightness_01.gif' etc.\n"
"where the first part of the name designates the colorspace used,\n"
"the second part says what is varied on the image\n"
"and the number codes the value of the quantity that is kept\n"
"constant in the image - 01 in the example means that the color\n"
"angle is 36 degrees = 1 * 360 degrees / 10\n";
}
int main(int argc, char ** argv)
{
if(argc <2)
{
usage(argv[0]);
return 1;
}
try
{
std::string colorspace(argv[1]);
if(colorspace == "lab")
{
createColorSpaceSlices("lab",
}
else if(colorspace == "luv")
{
createColorSpaceSlices("luv",
}
else if(colorspace == "ypbpr")
{
createColorSpaceSlices("ypbpr",
}
else if(colorspace == "ycbcr")
{
createColorSpaceSlices("ycbcr",
}
else if(colorspace == "yiq")
{
createColorSpaceSlices("yiq",
}
else if(colorspace == "yuv")
{
createColorSpaceSlices("yuv",
}
else
{
std::cerr << "Unknown colorspace: " << colorspace << std::endl;
usage(argv[0]);
return 1;
}
}
catch (std::exception & e)
{
std::cout << e.what() << std::endl;
return 1;
}
return 0;
}
Argument object for the function exportImage().
Definition imageinfo.hxx:134
Convert perceptual uniform CIE L*a*b* into linear (raw) RGB.
Definition colorconversions.hxx:1732
Convert perceptual uniform CIE L*u*v* into linear (raw) RGB.
Definition colorconversions.hxx:1668
Main MultiArray class containing the memory management.
Definition multi_array.hxx:2479
Convert linear (raw) RGB into non-linear (gamma corrected) R'G'B'.
Definition colorconversions.hxx:278
Class for a single RGB value.
Definition rgbvalue.hxx:128
value_type & red()
Definition rgbvalue.hxx:278
value_type & blue()
Definition rgbvalue.hxx:286
value_type & green()
Definition rgbvalue.hxx:282
Class for fixed size vectors.
Definition tinyvector.hxx:1008
Convert Y'CbCr color difference components into non-linear (gamma corrected) R'G'B'.
Definition colorconversions.hxx:2766
Convert Y'IQ color components into non-linear (gamma corrected) R'G'B'.
Definition colorconversions.hxx:2410
Convert Y'PbPr color difference components into non-linear (gamma corrected) R'G'B'.
Definition colorconversions.hxx:2227
Convert Y'UV color components into non-linear (gamma corrected) R'G'B'.
Definition colorconversions.hxx:2593
void exportImage(...)
Write an image to a file.
image import and export functions
TinyVector< float, 3 > polar2YPrimeCbCr(double color, double brightness, double saturation)
Init Y'CbCr color triple from polar representation.
Definition colorconversions.hxx:3193
TinyVector< float, 3 > polar2YPrimeIQ(double color, double brightness, double saturation)
Init Y'IQ color triple from polar representation.
Definition colorconversions.hxx:3280
TinyVector< float, 3 > polar2YPrimeUV(double color, double brightness, double saturation)
Init Y'UV color triple from polar representation.
Definition colorconversions.hxx:3365
TinyVector< float, 3 > polar2Lab(double color, double brightness, double saturation)
Init L*a*b* color triple from polar representation.
Definition colorconversions.hxx:2937
TinyVector< float, 3 > polar2Luv(double color, double brightness, double saturation)
Init L*u*v* color triple from polar representation.
Definition colorconversions.hxx:3023
TinyVector< float, 3 > polar2YPrimePbPr(double color, double brightness, double saturation)
Init Y'PbPr color triple from polar representation.
Definition colorconversions.hxx:3108