/** * \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; }
void ImageMean<T>::setup_pv(const ImageSequence& images) { // the image sequence must be consistent, or we cannot do // anything about it if (!consistent(images)) { throw std::runtime_error("images not consistent"); } // we need access to the pixels, but we want to avoid all the // time consuming dynamic casts, so we create a vector of // PixelValue objects, which already do the dynamic casts // in the constructor ImageSequence::const_iterator i; for (i = images.begin(); i != images.end(); i++) { pvs.push_back(PV(*i)); } }
/** * \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; }
/** * \brief Check that the image sequence is consistent * * Only a if all the images are of the same size we can actually compute * a calibration image. * \param images */ bool consistent(const ImageSequence& images) { // make sure all images in the sequence are of the same size ImageSequence::const_iterator i = images.begin(); for (i++; i != images.end(); i++) { if ((*images.begin())->size() != (*i)->size()) { debug(LOG_DEBUG, DEBUG_LOG, 0, "image size mismatch"); return false; } } // make sure all the images are monochrome images. There is now way // to calibrate color image, for (i = images.begin(); i != images.end(); i++) { if (isColorImage(*i)) { return false; } } return true; }
void ImageMean<T>::setup_images(const ImageSequence& images) { // create an image of appropriate size size = (*images.begin())->size(); image = new Image<T>(size); if (enableVariance) { // prepare the variance image var = new Image<T>(size); } else { var = NULL; } }
int main(int argc, char* argv[]){ fuseSingleImg(); return 0; ImageSequence* imgCapture = new ImageSequence(); imgCapture->init("C:/Logs/PCL/data/depth", ".png", "img_depth_"); imgCapture->open(); imgCapture->captureStart(); PoseTracker* pose_tracker = new PoseTracker(480,640); DeviceArray2D<unsigned short> depth_raw; IplImage* depthImg = 0; DeviceArray2D<PixelRGB> view_device_; vector<PixelRGB> viewer_host_; pcl::visualization::ImageViewer image_viewer_; //READ FILE vector<Matrix3frm> rot_vec; vector<Vector3f> tran_vec; //pose_tracker->readPoseToMemory("Pose.txt", rot_vec, tran_vec); pose_tracker->readPoseToMemory("C:/Logs/PCL/beingthere/resources/ExtrinsicPose.txt", rot_vec, tran_vec); //for(int i=0; i<10; ++i){ // cout << rot_vec.at(i) << endl; // cout << tran_vec.at(i) << endl; //} //getchar(); int count = 0; while(true){ ++count; imgCapture->captureNext(); depthImg = imgCapture->image(); //if(count % 5 != 0) continue; cout << count << endl; //cout << imgCapture->currentFile() << endl; depth_raw.upload(depthImg->imageData, 640*2, 480, 640); (*pose_tracker)(depth_raw, rot_vec[count], tran_vec[count]); //Eigen::Affine3f pose = pose_tracker->getCameraPose(); //cout << pose.linear() << endl; //cout << pose.translation() << endl; pose_tracker->getImage(view_device_); int cols; view_device_.download(viewer_host_, cols); image_viewer_.showRGBImage ((unsigned char*)&viewer_host_[0], view_device_.cols (), view_device_.rows ()); image_viewer_.spinOnce(); if(count >= 198) getchar(); getchar(); } //pose_tracker->writePoseToFile("Pose.txt"); getchar(); return 0; }
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; }
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"); } } }
/** * \brief Main function for makeflat tool * * This tool takes a list of image names on the command line, reads them, * and produces a flat image from them. */ int main(int argc, char *argv[]) { char *outfilename = NULL; const char *darkfilename = NULL; int c; while (EOF != (c = getopt(argc, argv, "do:D:?h"))) switch (c) { case 'd': debuglevel = LOG_DEBUG; break; case 'D': darkfilename = optarg; break; case 'o': outfilename = optarg; break; case '?': case 'h': usage(argv[0]); return EXIT_SUCCESS; default: throw std::runtime_error("bad option"); break; } // make sure we do have some files to process if (argc <= optind) { debug(LOG_ERR, DEBUG_LOG, 0, "no images specified"); std::cerr << "no image file arguments specified" << std::endl; } // read the images into memory ImageSequence images; for (; optind < argc; optind++) { debug(LOG_DEBUG, DEBUG_LOG, 0, "reading file %s", argv[optind]); std::string name(argv[optind]); FITSin infile(name); ImagePtr image = infile.read(); images.push_back(image); } // Get the dark image. This can come from a file, in which case we // have to read the image from the file ImagePtr dark; if (NULL != darkfilename) { debug(LOG_DEBUG, DEBUG_LOG, 0, "reading dark image: %s", darkfilename); std::string f = std::string(darkfilename); FITSin infile(f); dark = infile.read(); debug(LOG_DEBUG, DEBUG_LOG, 0, "got dark %d x %d", dark->size().width(), dark->size().height()); } else { dark = ImagePtr(new Image<float>(images[0]->size())); } // now produce the flat image FlatFrameFactory fff; ImagePtr flat; debug(LOG_DEBUG, DEBUG_LOG, 0, "computing flat image"); flat = fff(images, dark); // display some info about the flat image debug(LOG_DEBUG, DEBUG_LOG, 0, "flat image %d x %d generated", flat->size().width(), flat->size().height()); // write the flat image to a file if (outfilename) { debug(LOG_DEBUG, DEBUG_LOG, 0, "outfile: %s", outfilename); unlink(outfilename); FITSout outfile(outfilename); outfile.setPrecious(false); outfile.write(flat); debug(LOG_DEBUG, DEBUG_LOG, 0, "flat image written to %s", outfilename); } return EXIT_SUCCESS; }