Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
threshold.h
Go to the documentation of this file.
1 
21 #include <vector>
22 
23 #include <vigra/stdimage.hxx>
24 #include <vigra/transformimage.hxx>
25 
26 #include "deghosting.h"
27 
28 const uint16_t ONE_UNMASKED = 0;
29 const uint16_t THRESHOLD_DONTCARE = 1;
30 
41 std::vector<deghosting::BImagePtr> threshold(const std::vector<deghosting::FImagePtr> &inputImages, const double threshold, const uint16_t flags) {
42  std::vector<deghosting::BImagePtr> retVal;
43  const uint8_t minValue = 0;
44  const uint8_t maxValue = 255;
45 
46  // don't care about masking
47  if (flags & THRESHOLD_DONTCARE) {
48  for (unsigned int i=0; i < inputImages.size(); ++i) {
49  deghosting::BImagePtr tmpImg(new vigra::BImage(inputImages[i]->size()));
51  vigra::Threshold<vigra::FImage::PixelType, vigra::BImage::PixelType>(threshold, 255, 0, 255));
52  retVal.push_back(tmpImg);
53  }
54  return retVal;
55  }
56 
57  // arrays with iterators
58  std::vector<vigra::FImage::traverser> siterators(inputImages.size());
59  std::vector<vigra::BImage::traverser> diterators(inputImages.size());
60  // iterator to the end
61  vigra::FImage::traverser send = inputImages[0]->lowerRight();
62  // fill iterators and retVal
63  for (unsigned int i=0; i < inputImages.size(); ++i) {
64  // fill retVal
65  deghosting::BImagePtr tmpImg(new vigra::BImage(inputImages[i]->size()));
66  retVal.push_back(tmpImg);
67  // fill iterators
68  siterators[i] = inputImages[i]->upperLeft();
69  diterators[i] = retVal[i]->upperLeft();
70  }
71 
72  // leave pixels not masked in at least one image
73  // this is DEFAULT
74  // loop over row
75  while (siterators[0].y != send.y) {
76  // array with column iterators
77  std::vector<vigra::FImage::traverser> siteratorsX(inputImages.size());
78  std::vector<vigra::BImage::traverser> diteratorsX(inputImages.size());
79  for (unsigned int i=0; i < inputImages.size(); ++i) {
80  siteratorsX[i] = siterators[i];
81  diteratorsX[i] = diterators[i];
82  }
83  // now we can loop over the same pixels in all images at once
84  while (siteratorsX[0].x != send.x) {
85  // image with highest weight for the pixel
86  unsigned int highestI = 0;
87  for (unsigned int i=0; i<inputImages.size(); ++i) {
88  // apply threshold
89  if (*(siteratorsX[i]) < threshold)
90  *(diteratorsX[i]) = minValue;
91  else
92  *(diteratorsX[i]) = maxValue;
93  // highest search
94  highestI = (*(siteratorsX[highestI]) > *(siteratorsX[i])) ? highestI : i;
95  }
96  // set the highest one to maxValue;
97  *(diteratorsX[highestI]) = maxValue;
98 
99  // move all iterators by one pixel to the right
100  for (unsigned int i=0; i<inputImages.size(); ++i) {
101  ++siteratorsX[i].x;
102  ++diteratorsX[i].x;
103  }
104  }
105  // move all iterators to the next row
106  for (unsigned int i=0; i<inputImages.size(); ++i) {
107  ++siterators[i].y;
108  ++diterators[i].y;
109  }
110  }
111 
112  return retVal;
113 }
const uint16_t ONE_UNMASKED
Advanced threshold Copyright (C) 2009 Lukáš Jirkovský l.jirkovsky@gmail.com
Definition: threshold.h:28
std::shared_ptr< vigra::BImage > BImagePtr
Definition: deghosting.h:45
void transformImage(vigra::triple< SrcImageIterator, SrcImageIterator, SrcAccessor > src, vigra::triple< DestImageIterator, DestImageIterator, DestAccessor > dest, std::pair< AlphaImageIterator, AlphaAccessor > alpha, vigra::Diff2D destUL, TRANSFORM &transform, PixelTransform &pixelTransform, bool warparound, Interpolator interpol, AppBase::ProgressDisplay *progress, bool singleThreaded=false)
Transform an image into the panorama.
vigra::pair< typename ROIImage< Image, Alpha >::image_traverser, typename ROIImage< Image, Alpha >::ImageAccessor > destImage(ROIImage< Image, Alpha > &img)
Definition: ROIImage.h:324
vigra::triple< typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::ImageConstAccessor > srcImageRange(const ROIImage< Image, Mask > &img)
helper function for ROIImages
Definition: ROIImage.h:287
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition: threshold.h:41
const uint16_t THRESHOLD_DONTCARE
Definition: threshold.h:29
static uint16_t flags