Graphics Reference
In-Depth Information
// get local feature coordinate system in image1
vp.x = p2.x-p1.x;
vp.y = p2.y-p1.y;
wp.x = vp.y;
wp.y = -vp.x;
// compute local coordinates of pixel (i,j)
v.x = j-q1.x;
v.y = i-q1.y;
s = (v.x*vp.x + v.y*vp.y)/plength;
t = (v.x*wp.y - v.y*wp.x)/plength;
// map the pixel to the source image
jj = (int)(q1.x + s*v1.x + t*wp.x);
ii = (int)(q1.y + s*v1.y + t*wp.y);
// compute distance of pixel (Iii,jj) from line segment q1q2
If (s<0.0) {
v.x = jj - q2.x;
v.y = ii - w2.y;
t = sqrt(v.x*v.x + v.y*v.y);
}
else t = fabs(t*qlength);
t = pow(pow(qlength,p)/(a+t,b);
jdisp + = (jj-j)*t;
idisp + = (ii-i)*t;
weight + = t;
}
jdisp /= weight;
idisp /= weight;
ii = (int)(i+idisp);
jj = (int)(j+jdisp);
indexI = (WIDTH*i+j)*3;
if ((ii<0) || (ii>=HEIGHT) || (jj<0) || (jj>=WIDTH) ) {
image2[indexD] = background[0];
image2[indexD+1] = background[1];
image2[indexD+2] = background[2];
}
else {
indexS = (WIDTH*ii+jj)*3;
imageI[indexI] = image1[indexS];
imageI[indexI+1] = image1[indexS+1];
imageI[indexI+2] = image1[indexS+2];
}
}
}
}
FIGURE 4.51—Cont'd
Search WWH ::




Custom Search