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

Generated on 25 May 2016 for Hugintrunk by  doxygen 1.4.7