| |
Program Functions
110
ces (1,1), then the linear index increases by one from top to bottom. When the bottom is
reached, the next column is started at the top (1,2), and so on. Please also refer to the function
vXy2CtrlPtIndex.m.
vCu2U.m
This is an important function. It calculates the displacement fields for all pixels (u and v)
based on the displacement fields for the control points (cu and cv). As mentioned in the de-
scription of biline_weight, a matrix that stores the bilinear weights for all control points is
used to accomplish this task. Since this calculation is done often, i.e., for every deformation, it
should be done quickly. Therefore, if the matrix with bilinear weights is given to the function
as an argument, it has not to be calculated. If it is not given, then the function tries to use a
formerly calculated weights matrix. Before this can be done, it is ensured that the old weights
matrix was created for the right sizes. If the sizes do not agree, the weights matrix has to be
calculated, which may take some time. The code fragment below shows how the full dis-
placement fields are calculated in principal.
u = 0;
v = 0;
for j=1 : numCtrlPts
u = u + cu(j) * B(j);
v = v + cv(j) * B(j);
end
Principal calculation of u and
v from cu and cv; B(j) is the
image with the bilinear func-
tion for control point number
j
At the beginning of this programming project, the pixel displacement fields u and v were
calculated by using an iterative loop and a normal non-sparse matrix. Loops are very slow in
MATLAB. Therefore, the problem was vectorized. For the calculation of u and v, the use of a
sparse weight matrix, the vectorization, and the pre-allocation of memory lead to a speed im-
provement by a factor of about 1/126. Since the calculation of the displacement fields for all
|  |
|
| |
|
|