improve spectral resampling

parent 3284a379
......@@ -1790,6 +1790,7 @@ main (int argc, char **argv)
{
argvs_eval ("pal-to-set");
}
argvs_eval ("lab");
mrg_set_ui (mrg, ui, NULL);
mrg_main (mrg);
......
......@@ -725,29 +725,146 @@ luz_parse_spectrum (Luz *luz, char *spectrum)
float nm_start = num_array[0];
float nm_gap = num_array[1];
float nm_scale = num_array[2];
int bands = band - 3;
int i;
int j;
float nm = nm_start;
for (i = 3; i < band; i++)
float nm;
#define STRATEGY_NEAREST 0
#define STRATEGY_LINEAR 1
#define STRATEGY_TENT 2
int strategy = STRATEGY_TENT;
// 5nm:
// 1.5 TENT : 49.89287 97.56120 155.17508
// 1.0 TENT : 49.92163 98.19018 155.12943
// 0.5 TENT : 49.94464 98.69678 155.09358
// 0.3 TENT : 49.95459 98.91650 155.07816
// 0.2 TENT : 49.95920 99.01872 155.07101
// LINEAR : 49.96898 99.23534 155.05602
// NEAREST : 50.83529 99.49268 152.33022
// 10nm:
// 1.5 TENT : 49.73328 94.14050 155.44125
// 1.0 TENT : 50.00582 100.00207 154.99348
// 0.5 TENT : 49.93114 98.38665 155.11391
// 0.3 TENT : 49.96164 99.04399 155.06436
// 0.2 TENT : 49.97580 99.35043 155.04147
// LINEAR : 49.86871 96.60445 155.24734
// NEAREST : 50.00582 100.00207 154.99348
// 0.2 tent
// 5nm 49.96898 99.23535 155.05602
// 10nm 49.99241 99.77881 155.02098
// 0.1 tent
// 5nm 49.96898 99.23535 155.05602
// 10nm 50.00036 99.89520 155.00360
// 0.08 tent
// 5nm 49.96898 99.23535 155.05602
// 10nm 50.00309 99.94878 154.99847
// 0.05 tent
// 5nm 49.96898 99.23535 155.05602
// 10nm 50.00309 99.94878 154.99847
if (fabs (nm_gap - LUZ_SPECTRUM_GAP) < 0.1)
{
j = (int) ( (nm - LUZ_SPECTRUM_START) / LUZ_SPECTRUM_GAP + 0.5);
if (j >=0 && j < LUZ_SPECTRUM_BANDS)
strategy = STRATEGY_NEAREST;
}
else if (nm_gap < LUZ_SPECTRUM_GAP)
{
strategy = STRATEGY_TENT;
}
else if (nm_gap > LUZ_SPECTRUM_GAP)
{
strategy = STRATEGY_LINEAR;
}
switch (strategy)
{
case STRATEGY_TENT:
for (i = 0; i < LUZ_SPECTRUM_BANDS; i++)
{
double sum = 0.0;
double sum_parts = 0.0;
for (double ts = -0.08; ts < 0.08; ts+=0.001)
{
double part = (0.08-fabs(ts)) + 0.001;
double valA = 0.0;
double valB = 0.0;
double val;
double ip;
double d;
nm = LUZ_SPECTRUM_START + LUZ_SPECTRUM_GAP * (i+ts);
ip = (nm - nm_start) / nm_gap;
if (ip >= 0 && ip < bands)
valA = num_array[ (int)(3 + floor ( ip ))];
if (ip >= 0 && ip < bands - 1)
valB = num_array[ (int)(3 + floor ( ip + 1 ))];
d = ip - floor(ip);
val = valA * (1.0-d) + valB * d;
sum_parts += part;
sum += val * part;
}
s.bands[i] = sum/sum_parts * nm_scale;
}
break;
case STRATEGY_LINEAR:
for (i = 0; i < LUZ_SPECTRUM_BANDS; i++)
{
double valA = 0.0;
double valB = 0.0;
double val;
double ip;
double d;
nm = LUZ_SPECTRUM_START + LUZ_SPECTRUM_GAP * i;
ip = (nm - nm_start) / nm_gap;
if (ip >= 0 && ip < bands)
valA = num_array[ (int)(3 + floor ( ip ))];
if (ip >= 0 && ip < bands - 1)
valB = num_array[ (int)(3 + floor ( ip + 1 ))];
d = ip - floor(ip);
val = valA * (1.0-d) + valB * d;
s.bands[i] = val * nm_scale;
}
break;
case STRATEGY_NEAREST:
nm = nm_start;
for (i = 3; i < bands + 3; i++)
{
j = (int) ( (nm - LUZ_SPECTRUM_START) / LUZ_SPECTRUM_GAP + 0.5);
if (j >=0 && j < LUZ_SPECTRUM_BANDS)
{
int k;
for (k = j; k < LUZ_SPECTRUM_BANDS; k++)
s.bands[k] = num_array[i] * nm_scale;
}
nm += nm_gap;
}
j = (int) ( (nm - LUZ_SPECTRUM_START) / LUZ_SPECTRUM_GAP + 0.5);
if (j >=0 && j < LUZ_SPECTRUM_BANDS)
{
int k;
for (k = j; k < LUZ_SPECTRUM_BANDS; k++)
s.bands[k] = num_array[i] * nm_scale;
s.bands[k] = 0.0;
}
nm += nm_gap;
}
break;
j = (int) ( (nm - LUZ_SPECTRUM_START) / LUZ_SPECTRUM_GAP);
if (j >=0 && j < LUZ_SPECTRUM_BANDS)
{
int k;
for (k = j; k < LUZ_SPECTRUM_BANDS; k++)
s.bands[k] = 0.0;
}
}
}
}
return s;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment