/** * \brief Dark image construction function for arbitrary image sequences */ ImagePtr DarkFrameFactory::operator()(const ImageSequence& images) const { debug(LOG_DEBUG, DEBUG_LOG, 0, "processing %d images into dark frame", images.size()); // make sure we have at least one image if (images.size() == 0) { debug(LOG_ERR, DEBUG_LOG, 0, "cannot create dark from no images"); throw std::runtime_error("no images in sequence"); } // find out whether these are Bayer images, by looking at the first // image ImagePtr firstimage = *images.begin(); bool gridded = firstimage->getMosaicType().isMosaic(); debug(LOG_DEBUG, DEBUG_LOG, 0, "first image is %sgridded", (gridded) ? "" : "not "); // based on the bit size of the first image, decide whether to work // with floats or with doubles unsigned int floatlimit = std::numeric_limits<float>::digits; debug(LOG_DEBUG, DEBUG_LOG, 0, "float limit is %u", floatlimit); ImagePtr result; if (firstimage->bitsPerPlane() <= floatlimit) { result = dark<float>(images, gridded); } else { result = dark<double>(images, gridded); } if (firstimage->hasMetadata("INSTRUME")) { result->setMetadata(firstimage->getMetadata("INSTRUME")); } if (firstimage->hasMetadata("PROJECT")) { result->setMetadata(firstimage->getMetadata("PROJECT")); } result->setMosaicType(firstimage->getMosaicType()); return result; }
BinaryCube Binarizer::Binarize(const ImageSequence &is) { CHECK(!is.empty()); int width = is[0].cols; int height = is[0].rows; BinaryCube cube(width, height, is.size()); for (int z = 0; z < (int)is.size(); ++z) { const cv::Mat &image = is[z]; CHECK_EQ(2, image.dims); CHECK_EQ(1, image.channels()); CHECK_EQ(width, image.cols); CHECK_EQ(height, image.rows); cv::Mat bin; // newval = maxval if val > thresh else 0 cv::threshold(image, bin, /* thresh = */ 127, /* maxval = */ 255, cv::THRESH_BINARY); for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { cube[x][y][z] = bin.at<uint8_t>(y, x); } } } return cube; }
/** * \brief Main method for the stacker program */ int main(int argc, char *argv[]) { int c; int longindex; const char *outfilename = NULL; while (EOF != (c = getopt_long(argc, argv, "dh?o:", longopts, &longindex))) { switch (c) { case 'd': debuglevel = LOG_DEBUG; break; case 'o': outfilename = optarg; break; case 'h': case '?': usage(argv[0]); return EXIT_SUCCESS; } } // read all the images ImageSequence images; for (; optind < argc; optind++) { FITSin in(argv[optind]); ImagePtr image = in.read(); images.push_back(image); } debug(LOG_DEBUG, DEBUG_LOG, 0, "found %d images for sequence", images.size()); // now do the stacking astro::image::stacking::Stacker stacker; ImagePtr stackedimage = stacker(images); // write the result image if(NULL != outfilename) { FITSout out(outfilename); out.write(stackedimage); } else { std::cerr << "no output filename, not writing result image" << std::endl; } // that's it return EXIT_SUCCESS; }
void uvctest::testExposure() { debug(LOG_DEBUG, DEBUG_LOG, 0, "get the first camera device"); CameraPtr camera = locator->getCamera(0); int ccdindex = default_ccdid; debug(LOG_DEBUG, DEBUG_LOG, 0, "get the CCD no %d", ccdindex); CcdPtr ccd = camera->getCcd(ccdindex); Exposure exposure(ccd->getInfo().getFrame(), default_exposuretime); debug(LOG_DEBUG, DEBUG_LOG, 0, "start an exposure: %s", exposure.toString().c_str()); ccd->startExposure(exposure); ccd->exposureStatus(); debug(LOG_DEBUG, DEBUG_LOG, 0, "retrieve an image"); ImageSequence imgseq = ccd->getImageSequence(2); ImagePtr image = imgseq[imgseq.size() - 1]; debug(LOG_DEBUG, DEBUG_LOG, 0, "image retrieved"); // write the image to a file unlink("test.fits"); FITSout file("test.fits"); file.write(image); if (ccdindex == 2) { DemosaicBilinear<unsigned char> demosaicer; Image<unsigned char> *mosaicimg = dynamic_cast<Image<unsigned char> *>(&*image); if (NULL != mosaicimg) { Image<RGB<unsigned char> > *demosaiced = demosaicer(*mosaicimg); ImagePtr demosaicedptr(demosaiced); unlink("test-demosaiced.fits"); FITSout demosaicedfile("test-demosaiced.fits"); demosaicedfile.write(demosaicedptr); } else { debug(LOG_ERR, DEBUG_LOG, 0, "not a mosaic image"); } } }