threshold.h

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

Generated on 1 Aug 2015 for Hugintrunk by  doxygen 1.4.7