Example for HomographyMapping usage.
#include <Image/HomographyMapping.hh>
#include <Image/AffineMapping.hh>
#include <Image/DisplacementMapping.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Debug/TimeMeasure.hh>
#include <Base/Math/Random.hh>
using namespace BIAS;
using namespace std;
int main(int argc, char *argv[])
{
cout<<endl<<"Usage: "<<argv[0]
<<" [testimage [ width height [homography.mat]]]"<<endl<<endl;
cout<<"If you dont provide a test image, I will generate one :-)"
<<endl<<endl;
if (argc>=2) {
BIASERR("error loading "<<argv[1]);
return -2;
}
}
if (argc>4) {
cout<<"Reading HMatrix "<<argv[4]<<endl;
cout<<"H is "<<H<<endl;
H.GetInverse(tmp);
H = tmp;
} else {
double angle = -45.0 / 180.0 * M_PI;
double angle2 = 3.0 / 180.0 * M_PI;
HRot[0][0]= cos(angle); HRot[0][1] = sin(angle);
HRot[1][0]= -sin(angle); HRot[1][1]= cos(angle);
HRot2[0][0]= cos(angle2); HRot2[0][1] = sin(angle2);
HRot2[1][0]= -sin(angle2); HRot2[1][1]= cos(angle2);
HScale[0][0] = 4.0; HScale[1][1] = 1.0;
H = HRot2 * HRot.
Transpose() * HScale * HRot;
cout<<"Using default homography "<<H<<endl;
}
if (argc<2){
cout<<"Generating test image orig.mip"<<endl;
bool highFreqCross = true;
Hinv *= 1.0 / H[2][2];
} else {
BIASERR("error loading "<<argv[1]);
return -2;
}
}
if (argc>3) {
width = atoi(argv[2]);
height = atoi(argv[3]);
cout<<"Using imagesize "<<width<<" x "<<height<<endl;
} else {
cout<<"Using input image size "<<width<<" x "<<height<<endl;
}
HMove[0][2]= double(im.
GetWidth())/-2.0;
HMove2[0][2]= double(width)/-2.0; HMove2[1][2] = double(height)/-2.0;
H = HMoveInv * H * HMove2;
cout<<
"ROI of source image is "<<*im.
GetROI()
<<" while image size is "<<width<<" x "<<height<<endl;
#ifdef AFFINE
#else
#endif
for(
unsigned int i=0;i<im.
GetChannelCount();i++) color[i]=(
unsigned char)255;
imresbilinear.FillImageWithConstValue(color);
imrestrilinear.FillImageWithConstValue(color);
imresnearest_dismap.FillImageWithConstValue(color);
imresnearest_lookup.FillImageWithConstValue(color);
imresbilinear_lookup.FillImageWithConstValue(color);
imrestrilinear_lookup.FillImageWithConstValue(color);
imresbicubic.FillImageWithConstValue(color);
imresanisotropic.FillImageWithConstValue(color);
imresdirect.FillImageWithConstValue(color);
delete[] color;
NN_dismap (width, height, 3);
#ifdef AFFINE
Mapper.SetAffineTransformation(H[0][0],H[0][1],H[1][0], H[1][1],
H[0][2],H[1][2]);
#else
#endif
#ifdef AFFINE
Mapper.MapDirect(im, imresdirect);
#endif
unsigned char* Data = imresnearest_dismap.GetImageData();
int counter = 0;
int counter_index = 0;
double bias_x, bias_y;
for(unsigned int j = 0; j < imresnearest_dismap.GetHeight(); j++){
for(unsigned int i = 0; i < imresnearest_dismap.GetWidth(); i++){
p_sink[0] = i;
p_sink[1] = j;
p_sink[2] = 1.0;
int p_x = (int)rint(bias_x);
int p_y = (int)rint(bias_y);
int p_z = (int)(p_src[2]);
if(p_z != -1 &&
p_x >= 0 &&
p_y >= 0 &&
counter_index = im.
GetWidth()*p_y + p_x;
}
else
*Data++ = (unsigned char)(0);
}
counter++;
}
}
cout<<"timing ..."<<endl<<flush;
unsigned int numbermeasurements = 1;
for (unsigned int i=0; i<numbermeasurements; i++) {
#ifdef TIMING
BIASWARN("Anisoptropic filtering causes double free or corruption error.")
#endif //TIMING
#ifdef AFFINE
Mapper.MapDirect(im, imresdirect);
#endif
}
cout <<"Anisotropic mapping took "
<<" ms, "<<endl
<<"Bicubic mapping took "
<<" ms,"<<endl
<<"NN-mapping (no lookups) took "
<<" ms"<< endl
<<"NN-mapping (wt lookups) init took "
<<" ms," << endl
<<"NN-mapping (wt lookups) took "
<<" ms," << endl
<<"Bilinear mapping (no lookups) took "
<<" ms,"<<endl
<<"Bilinear mapping (wt lookups) init took "
<<" ms,"<<endl
<<"Bilinear mapping (wt lookups) took "
<<" ms,"<<endl
<<"Trilinear mapping (no lookups) took "
<<" ms,"<<endl
<<"Trilinear mapping (wt lookups) init took "
<<" ms,"<<endl
<<"Trilinear mapping (wt lookups) took "
<<" ms,"<<endl
#ifdef AFFINE
<<"Direct affine took "
#endif
<<endl;
if (
ImageIO::Save(
"image_homography_anisotropic.mip", imresanisotropic)!=0){
BIASERR("error image");
return -3;
}
if (
ImageIO::Save(
"image_homography_trilinear.mip", imrestrilinear)!=0){
BIASERR("error image");
return -3;
}
imrestrilinear_lookup)!=0){
BIASERR("error image");
return -3;
}
if (
ImageIO::Save(
"image_homography_bicubic.mip", imresbicubic)!=0){
BIASERR("error image");
return -3;
}
if (
ImageIO::Save(
"image_homography_bilinear.mip", imresbilinear)!=0){
BIASERR("error image");
return -3;
}
imresbilinear_lookup)!=0){
BIASERR("error image");
return -3;
}
if (
ImageIO::Save(
"image_homography_nearest.mip", imresnearest)!=0){
BIASERR("error image");
return -3;
}
imresnearest_lookup)!=0){
BIASERR("error image");
return -3;
}
imresnearest_dismap)!=0){
BIASERR("error image");
return -3;
}
#ifdef AFFINE
BIASERR("error image");
return -3;
}
#endif
return 0;
}