色彩轉換公式誤差驗證
#include <iostream>
using namespace std;
int main()
{
float val, vmax, vmin;
for (int r=0; r<256 ; ++r)
for (int g=0; g<256 ; ++g)
for (int b=0; b<256 ; ++b)
{
//val = g - (r+b)/2.0;
//val = r - (g+b)/2.0;
//val = (r+g)/2.0 - abs(r-g)/2.0 - b;
//val = b - (r+g)/2.0;
// (r-g) / max(r,g,b)
float maxcolor = r>g?r:g;
if (b > maxcolor)
maxcolor = b;
val = (maxcolor/255.0 < 0.1) ? 0.0 : ((r-g)/maxcolor);
if (r+g+b==0)
{
vmax = val;
vmin = val;
}
else
{
if (val > vmax)
vmax = val;
if (val < vmin)
vmin = val;
}
}
cout << "max=" << vmax << endl;
cout << "min=" << vmin << endl;
cout << "range=" << vmax - vmin << endl;
system("pause");
return 0;
}
留言