threshold.h

Go to the documentation of this file.
00001 
00021 #include <vector>
00022 
00023 #include <boost/shared_ptr.hpp>
00024 #include <vigra/stdimage.hxx>
00025 #include <vigra/transformimage.hxx>
00026 
00027 #include "deghosting.h"
00028 
00029 using std::vector;
00030 using namespace vigra;
00031 using namespace deghosting;
00032 
00033 const uint16_t ONE_UNMASKED       = 0;
00034 const uint16_t THRESHOLD_DONTCARE = 1;
00035 
00046 vector<BImagePtr> threshold(const vector<FImagePtr> &inputImages, const double threshold, const uint16_t flags) {
00047     vector<BImagePtr> retVal;
00048     const uint8_t minValue = 0;
00049     const uint8_t maxValue = 255;
00050     
00051     // don't care about masking
00052     if (flags & THRESHOLD_DONTCARE) {
00053         for (unsigned int i=0; i < inputImages.size(); ++i) {
00054             BImagePtr tmpImg(new BImage(inputImages[i]->size()));
00055             transformImage(srcImageRange(*tmpImg), destImage(*tmpImg),
00056                             Threshold<FImage::PixelType, BImage::PixelType>(threshold, 255, 0, 255));
00057             retVal.push_back(tmpImg);
00058         }
00059         return retVal;
00060     }
00061     
00062     // arrays with iterators
00063     vector<FImage::traverser> siterators(inputImages.size());
00064     vector<BImage::traverser> diterators(inputImages.size());
00065     // iterator to the end
00066     FImage::traverser send = inputImages[0]->lowerRight();
00067     // fill iterators and retVal
00068     for (unsigned int i=0; i < inputImages.size(); ++i) {
00069         // fill retVal
00070         BImagePtr tmpImg(new BImage(inputImages[i]->size()));
00071         retVal.push_back(tmpImg);
00072         // fill iterators
00073         siterators[i] = inputImages[i]->upperLeft();
00074         diterators[i] = retVal[i]->upperLeft();
00075     }
00076     
00077     // leave pixels not masked in at least one image
00078     // this is DEFAULT
00079     // loop over row
00080     while (siterators[0].y != send.y) {
00081         // array with column iterators
00082         vector<FImage::traverser> siteratorsX(inputImages.size());
00083         vector<BImage::traverser> diteratorsX(inputImages.size());
00084         for (unsigned int i=0; i < inputImages.size(); ++i) {
00085             siteratorsX[i] = siterators[i];
00086             diteratorsX[i] = diterators[i];
00087         }
00088         // now we can loop over the same pixels in all images at once
00089         while (siteratorsX[0].x != send.x) {
00090             // image with highest weight for the pixel
00091             unsigned int highestI = 0;
00092             for (unsigned int i=0; i<inputImages.size(); ++i) {
00093                 // apply threshold
00094                 if (*(siteratorsX[i]) < threshold)
00095                     *(diteratorsX[i]) = minValue;
00096                 else
00097                     *(diteratorsX[i]) = maxValue;
00098                 // highest search
00099                 highestI = (*(siteratorsX[highestI]) > *(siteratorsX[i])) ? highestI : i;
00100             }
00101             // set the highest one to maxValue;
00102             *(diteratorsX[highestI]) = maxValue;
00103             
00104             // move all iterators by one pixel to the right
00105             for (unsigned int i=0; i<inputImages.size(); ++i) {
00106                 ++siteratorsX[i].x;
00107                 ++diteratorsX[i].x;
00108             }
00109         }
00110         // move all iterators to the next row
00111         for (unsigned int i=0; i<inputImages.size(); ++i) {
00112             ++siterators[i].y;
00113             ++diterators[i].y;
00114         }
00115     }
00116     
00117     return retVal;
00118 }

Generated on Tue Sep 23 01:25:30 2014 for Hugintrunk by  doxygen 1.3.9.1