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

example for using the pyramid images

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 ExamplePyramidImage.cpp
@relates PyramidImage
@brief example for using the pyramid images
@ingroup g_examples
@author MIP
*/
#include <Base/Debug/Debug.hh>
#include <Base/Image/ImageConvert.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Debug/TimeMeasure.hh>
#include <Image/PyramidImage.hh>
#include <Utils/Param.hh>
using namespace BIAS;
using namespace std;
int main(int argc, char *argv[])
{
// initialize parameters
BIAS::Param param;
param.DisableDestructorWarning(); // no warning at exit
// add parameters (as unclassified parameter group)
param.AddParamBool("help","prints info about all parameters", false, 'h');
param.AddParamString("image", "image file to load", "", 'i');
param.AddParamString("output", "output file prefix", "", 'o');
param.AddParamInt("size", "pyramid size", 4, 1, 256, 's');
param.AddParamDouble("factor", "resampling factor per step", 2.0, 1.0, 1e6, 'f');
// get command line parameters
param.ParseCommandLine(argc, argv);
// print help information
if (*param.GetParamBool("help") == true) {
cout << endl;
param.Usage();
exit(0);
}
// show image if given
const std::string imageName = *param.GetParamString("image");
if (imageName.empty()) {
cout << "no input image specified (try --help)" << endl;
return 0;
}
// read and show image
int res = BIAS::ImageIO::Load(imageName, image);
if (res != 0) {
BIASERR("error loading image " << imageName);
return -1;
} else {
cout << "loaded image " << imageName << endl;
}
ImageConvert::IP_ToGrey(image); // convert to grey image
}
// initialize time measurement
// initialize pyramid image
int pyramidSize = *param.GetParamInt("size");
double pyramidDownsamplingFactor = *param.GetParamDouble("factor");
pyramid.SetRescaleFactor(pyramidDownsamplingFactor);
pyramid.Init(image.GetWidth(), image.GetHeight(), 1, pyramidSize);
pyramid.SetZero();
// downsampling
timer.Start();
*pyramid[0] = image;
pyramid.Downsample();
timer.Stop();
cout << "calculation of pyramid image with size " << pyramid.size()
<< " for image with size " << image.GetWidth() << "x"
<< image.GetHeight() << " took " << 1e-3*timer.GetRealTime()
<< " ms" << endl;
// write output
const std::string outputPrefix = *param.GetParamString("output");
if (!outputPrefix.empty())
{
int res = pyramid.WriteImages(outputPrefix);
if (res != 0) {
BIASERR("error writing pyramid image " << outputPrefix);
} else {
cout << "saved pyramid image to " << outputPrefix << "-pl*.mip" << endl;
}
} else {
cout << "use --output to save output images to disk" << endl;
}
return 0;
}