本文整理汇总了C++中Background::G方法的典型用法代码示例。如果您正苦于以下问题:C++ Background::G方法的具体用法?C++ Background::G怎么用?C++ Background::G使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Background
的用法示例。
在下文中一共展示了Background::G方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
int main(int argc, char *argv[]) {
int c;
int longindex;
std::string outfilename;
bool force = false;
float alpha = 0.001;
while (EOF != (c = getopt_long(argc, argv, "a:dfho:", longopts,
&longindex)))
switch (c) {
case 'a':
alpha = std::stof(optarg);
break;
case 'd':
debuglevel = LOG_DEBUG;
break;
case 'f':
force = true;
break;
case 'h':
usage(argv[0]);
return EXIT_SUCCESS;
case 'o':
outfilename = std::string(optarg);
break;
default:
throw std::runtime_error("unknown option");
}
// get the file name
if (argc <= optind) {
throw std::runtime_error("input file name missing");
}
std::string infilename(argv[optind++]);
debug(LOG_DEBUG, DEBUG_LOG, 0, "processing image %s",
infilename.c_str());
// read the input file
FITSin infile(infilename);
ImagePtr image = infile.read();
ImagePtr outimage;
// prepare a background extractor
BackgroundExtractor extractor(alpha);
// if this is a mono image, we just use luminance for background
// extraction
switch (image->planes()) {
case 1: {
// make image accessible as an image with float pixels
ConstPixelValueAdapter<float> from(image);
// get the background
Background<float> bg = extractor(image->center(), true,
BackgroundExtractor::QUADRATIC, from);
// subtract the background
BackgroundFunctionAdapter bfa(from, bg.G());
// write the result to the output
outimage = ImagePtr(new Image<float>(bfa));
}
break;
case 3: {
// make image accessible as an RGB<float> image
ConstPixelValueAdapter<RGB<float> > from(image);
// get the background
Background<float> bg = extractor(image->center(), true,
BackgroundExtractor::QUADRATIC, from);
// subtract the background
BackgroundSubtractionAdapter bsa(from, bg);
// write the result to the output
outimage = ImagePtr(new Image<RGB<float> >(bsa));
}
break;
default:
std::string msg = stringprintf("don't know how to handle "
"background for images with %d planes",
image->planes());
debug(LOG_ERR, DEBUG_LOG, 0, "%s", msg.c_str());
throw std::runtime_error(msg);
}
// we give up here, because we don't want to write the changed file
if (0 == outfilename.size()) {
return EXIT_SUCCESS;
}
FITSout outfile(outfilename);
outfile.setPrecious(!force);
outfile.write(outimage);
// that's it
return EXIT_SUCCESS;
}