Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleCylinderMapping.cpp

Example for mapping an image with BIAS::CylinderMapping

Author
MIP
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
@example ExampleCylinderMapping.cpp
@relates CylinderMapping
@brief Example for mapping an image with BIAS::CylinderMapping
@ingroup g_examples
@author MIP
*/
#include <string>
#include <iostream>
// bias includes
#include <Utils/Param.hh>
#include <Base/Image/ImageIO.hh>
#include <Image/CylinderMapping.hh>
#include <Base/Debug/TimeMeasure.hh>
using namespace BIAS;
using namespace std;
int main(int args, char **arg)
{
// initialize parameters
BIAS::Param param;
param.DisableDestructorWarning(); // no warning at exit
// add parameterss (as unclassified parameter group)
param.AddParamBool("help","prints info about all parameters", false, 'h');
param.AddParamString("image", "image file to load", "", 'i');
param.AddParamDouble("focal", "focal length", 100.0, -1, 1e6,'f');
param.AddParamDouble("hx", "principal point x", -1, -1, 1e6);
param.AddParamDouble("hy", "principal point y", -1, -1, 1e6);
std::vector<int> vecMethodIDs;
std::vector<string> vecMethodNames;
vecMethodIDs.push_back((int)MapBilinear);
vecMethodNames.push_back("bi");
vecMethodIDs.push_back((int)MapTrilinear);
vecMethodNames.push_back("tri");
param.AddParamEnum("method", "interpolation method (bi, tri)",
vecMethodNames, (int)MapTrilinear, &vecMethodIDs, 'm');
// get command line parameters
param.ParseCommandLine(args, arg);
// print help information
if ( *param.GetParamBool("help") == true ) {
cout << endl;
param.Usage();
exit(0);
}
// show image if given
if ( param.GetParamString("image")->empty() ) {
cout << "no input image specified (try --help)" << endl;
return 0;
}
// read and show image
int r = BIAS::ImageIO::Load(*param.GetParamString("image"),image);
if ( r != 0 ) {
BIASERR("error loading image: "<<(*param.GetParamString("image")));
}
target(image.GetWidth(), image.GetHeight(), image.GetChannelCount());
target.Clear(0);
cout << "image width = " << image.GetWidth() << endl;
cout << "image height = " << image.GetHeight() << endl;
// set the interpolation method
(InterpolationMethod)(*(param.GetParamEnum("method")));
// set the principal point of the cylinder camera
double hx = *(param.GetParamDouble("hx"));
if (hx > 0) cout << "Setting hx to " << hx << endl;
double hy = *(param.GetParamDouble("hy"));
if (hy > 0) cout << "Setting hy to " << hy << endl;
// initialize time measurement
// perform the mapping
CylinderMapping mapping;
if (hx > 0 && hy > 0) mapping.setPrincipalPoint(hx, hy);
mapping.setFocalLength(*param.GetParamDouble("focal"),
*param.GetParamDouble("focal"));
timer.Start();
mapping.Map(image, target, method);
timer.Stop();
cout<<"Time consumed for mapping: "<<1e-3*timer.GetRealTime()<<" ms\n";
/*
const int times = 100;
double timeSum = 0, timeSqSum = 0;
for (int t = 1; t <= times; t++) {
timer.Reset();
timer.Start();
smapping.Map(image, target, method);
timer.Stop();
const double time = 1e-3*timer.GetRealTime();
timeSum += time;
timeSqSum += (time*time);
cout<<"Time consumed for mapping: " << timeSum/(double)t << " +- "
<< sqrt(timeSqSum/(double)t - (timeSum*timeSum)/(double)(t*t))
<< " ms in " << t << "/" << times << " repetitions.\n";
}
*/
BIAS::ImageIO::Save("ExampleCylinderMapping.mip", target);
cout<<"Mapped image written to ExampleCylinderMapping.mip"<<endl;
}