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>
using namespace vigra;
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;
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;
}