RESAMPLING OF 2D/3D IMAGES

Grégoire Malandain


Code

A small library (written in C) allowing 2D or 3D image resampling using a 4x4 matrix. The value of a point in the result image is estimated is available by anonymous FTP for non-commercial uses only.

Examples obtained with the code

Original grey level image

A 4 by 4 transformation matrix M (with homogenous coordinates) is of the form

M = R00 R01 R02 T0
R10 R11 R12 T1
R20 R21 R22 T2
0 0 0 1
The Rij define an affine matrix (rotation in case of rigid transformation), while the Ti define a translation vector. The transformation of a point M = (x,y,z) into M' = (x',y',z') is done using
x' = M x
y' y
z' z
1 1
which is equivalent to
x' = R x + T
y' y
z' z
The principle of resampling is then to compute, for each point (of integer coordinates) in the result image its correspondant (of real coordinates) in the original image, and to estimate the grey level value of the correspondant. Thus, the transformation from the original image into the result image is the inverse of the given matrix. Consider the matrix
M = 0.8660254 -0.5 0.0 80.5147742
0.5 0.8660254 0.0 -46.4852258
0.0 0.0 1.0 1.0
0 0 0 1
It correspond to a 2D rigid transformation with a rotation of 30 degrees (X axis is from left to right, Y axis is from top to bottom) of center (127,127) (invariant point for the transformation). Using directly this matrix with the resampling program yields a rotation of -30 degrees as shown below.
%test-reech-pnm greg-rmn.pgm greg-rmn-reech1.ppm -mat matrix.example
By inverting the matrix, one may obtained the desired 30 degrees rotation
%test-reech-pnm greg-rmn.pgm greg-rmn-reech2.ppm -mat matrix.example -inv

Interpolation using the nearest value
Command lines as the same as above except that the option -nearest has been added
This option is quite useful when one want to resample labels images (see example in the connected components page).
Initial image
Linear resampling
New grey levels appear at borders
Nearest neighbor resampling
Only the original grey levels are used

Gregoire Malandain
Last modified: Mon Jun 26 10:43:00 MET DST 2000