Fix the trilinear interpolation, and its test.

This commit is contained in:
Laurent Rineau 2008-10-30 14:11:01 +00:00
parent 11cd0ee8e3
commit a63ed4f05f
2 changed files with 40 additions and 46 deletions

View File

@ -198,9 +198,10 @@ Image_3::trilinear_interpolation(const Coord_type& x,
const int dimz = zdim(); const int dimz = zdim();
const int dimxy = dimx*dimy; const int dimxy = dimx*dimy;
const int i1 = (int)(z / image()->vx); // images are indexed by (z,y,x)
const int i1 = (int)(z / image()->vz);
const int j1 = (int)(y / image()->vy); const int j1 = (int)(y / image()->vy);
const int k1 = (int)(x / image()->vz); const int k1 = (int)(x / image()->vx);
const int i2 = i1 + 1; const int i2 = i1 + 1;
const int j2 = j1 + 1; const int j2 = j1 + 1;
const int k2 = k1 + 1; const int k2 = k1 + 1;
@ -209,16 +210,17 @@ Image_3::trilinear_interpolation(const Coord_type& x,
* a, b, c, d, e, f, g, h are the value of the image at the corresponding * a, b, c, d, e, f, g, h are the value of the image at the corresponding
* voxels: * voxels:
* *
* z *
* | e______ h * x z
* | /
* f___ __ g
* /| /| * /| /|
* f/_|____g/ | * e/_|____h/ |
* | | | | * | | | |
* | |a___|_d| * | |b___|_c|
* | / | / * | / | /
* b|/_____c|/ _y * a|/_____d|/ _y
* *
* x/
* *
* a = val(i1, j1, k1) * a = val(i1, j1, k1)
* b = val(i2, j1, k1) * b = val(i2, j1, k1)
@ -237,7 +239,7 @@ Image_3::trilinear_interpolation(const Coord_type& x,
z < 0.f || z < 0.f ||
i1 >= dimx || i1 >= dimx ||
j1 >= dimy || j1 >= dimy ||
k1 >= dimy) k1 >= dimz)
{ {
return outside; return outside;
} }
@ -314,12 +316,12 @@ Image_3::trilinear_interpolation(const Coord_type& x,
} }
} }
const Target_word_type di2 = i2 - x; const Target_word_type di2 = i2 - z;
const Target_word_type di1 = x - i1; const Target_word_type di1 = z - i1;
const Target_word_type dj2 = j2 - y; const Target_word_type dj2 = j2 - y;
const Target_word_type dj1 = y - j1; const Target_word_type dj1 = y - j1;
const Target_word_type dk2 = k2 - z; const Target_word_type dk2 = k2 - x;
const Target_word_type dk1 = z - k1; const Target_word_type dk1 = x - k1;
// std::cerr << di2 << " " << di1 << "\n"; // std::cerr << di2 << " " << di1 << "\n";
// std::cerr << dj2 << " " << dj1 << "\n"; // std::cerr << dj2 << " " << dj1 << "\n";
// std::cerr << dk2 << " " << dk1 << "\n"; // std::cerr << dk2 << " " << dk1 << "\n";

View File

@ -15,40 +15,14 @@ int main() {
ImageIO_free(image.data()); ImageIO_free(image.data());
image.set_data(&data[0]); image.set_data(&data[0]);
_image* im = image.image();
// im->xdim = 2;
// im->ydim = 2;
// im->zdim = 2;
// im->vdim = 1;
// im->vx = 1;
// im->vy = 1;
// im->vz = 1;
// im->cx = im->cy = im->cz = 0;
// im->tx = im->ty = im->tz = 0.0;
// im->rx = im->ry = im->rz = 0.0;
// im->fd = NULL;
// im->openMode = OM_CLOSE;
// im->endianness = END_UNKNOWN;
// im->dataMode = DM_BINARY;
// // word type (unsigned char)
// im->wdim = 1;
// im->wordKind = WK_FIXED;
// im->vectMode = VM_SCALAR;
// im->sign = SGN_UNSIGNED;
// im->imageFormat = NULL;
std::cerr << std::setprecision(2) << std::fixed; std::cerr << std::setprecision(2) << std::fixed;
for(int x = 0; x <= 1; ++x) for(int x = 0; x <= 1; ++x)
for(int y = 0; y <= 1; ++y) for(int y = 0; y <= 1; ++y)
for(int z = 0; z <= 1; ++z) for(int z = 0; z <= 1; ++z)
{ {
data[x * 4 + y * 2 + z] = 1; data[z * 4 + y * 2 + x] = 1;
std::cerr << "#### data" std::cerr << "#### data"
<< "[" << x << "]" << "[" << x << "]"
@ -63,10 +37,10 @@ int main() {
assert((int)d_y == 0); assert((int)d_y == 0);
assert((int)d_z == 0); assert((int)d_z == 0);
const double value = const double value =
image.trilinear_interpolation<Word, double, float>(d_x, image.trilinear_interpolation<Word, double, double>(d_x,
d_y, d_y,
d_z, d_z,
255); 255);
std::cerr << "val(" << d_x << ", " << d_y << " , " << d_z << ") = " std::cerr << "val(" << d_x << ", " << d_y << " , " << d_z << ") = "
<< value << std::endl; << value << std::endl;
const double sq_dist = const double sq_dist =
@ -83,9 +57,27 @@ int main() {
assert(value >= 0.12); assert(value >= 0.12);
else else
assert(value <= 0.001); assert(value <= 0.001);
const float value2 =
image.trilinear_interpolation<Word, float, float>(d_x,
d_y,
d_z,
0);
const float value3 = triLinInterp(image.image(),
d_x,
d_y,
d_z,
0.f);
std::cerr << "tri(" << d_x << ", " << d_y << " , " << d_z << ") = "
<< value3 << std::endl;
if(value2 != value3)
std::cerr << std::setprecision(30)
<< " " << value2 << "\n!= " << value3 << std::endl;
assert(value2 == value3);
} }
data[x * 4 + y * 2 + z] = 0; data[z * 4 + y * 2 + x] = 0;
} }
image.set_data(0); image.set_data(0);
} }