Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImageRemapper.h
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
27 #ifndef _NONA_IMAGEREMAPPER_H
28 #define _NONA_IMAGEREMAPPER_H
29 
30 
31 #include <panodata/PanoramaData.h>
32 #include <nona/RemappedPanoImage.h>
33 #include <vigra_ext/impexalpha.hxx>
34 
35 namespace HuginBase {
36 namespace Nona {
37 
38 
40  template <typename ImageType, typename AlphaType>
42  {
43 
44  public:
46  {};
47 
53  const PanoramaOptions & opts,
54  unsigned int imgNr,
55  vigra::Rect2D outputROI,
56  AppBase::ProgressDisplay* progress) = 0;
57 
58  virtual ~SingleImageRemapper() {};
59 
61  {
62  m_advancedOptions = advancedOptions;
63  }
64 
67  protected:
69 
70  };
71 
72 
74  template <typename ImageType, typename AlphaType>
75  class FileRemapper : public SingleImageRemapper<ImageType, AlphaType>
76  {
77 
78  public:
80  {
81  m_remapped = 0;
82  }
83 
84  virtual ~FileRemapper() {};
85 
86  typedef std::vector<float> LUT;
87 
88 
89  public:
91  void loadImage(const PanoramaOptions & opts,
92  vigra::ImageImportInfo & info, ImageType & srcImg,
93  AlphaType & srcAlpha)
94  {}
95 
98  getRemapped(const PanoramaData & pano, const PanoramaOptions & opts,
99  unsigned int imgNr, vigra::Rect2D outputROI,
100  AppBase::ProgressDisplay* progress);
101 
104  { delete d; }
105 
106 
107  protected:
109 
110  };
111 
112 
113 
115  template <class FFType, class SrcIter, class SrcAccessor, class DestIter, class DestAccessor>
116  void applyFlatfield(vigra::triple<SrcIter, SrcIter, SrcAccessor> srcImg,
117  vigra::pair<DestIter, DestAccessor> destImg,
118  vigra::ImageImportInfo & ffInfo,
119  double gamma,
120  double gammaMaxVal,
121  bool division,
122  typename vigra::NumericTraits<typename SrcAccessor::value_type>::RealPromote a,
123  typename vigra::NumericTraits<typename SrcAccessor::value_type>::RealPromote b,
124  bool dither);
125 
126 
127 
128 }; // namespace
129 }; // namespace
130 
131 
132 
133 
134 //==============================================================================
135 // templated implementations
136 
137 
138 #include <vigra/functorexpression.hxx>
140 
141 
142 namespace HuginBase {
143 namespace Nona {
144 
145 
146 template <typename ImageType, typename AlphaType>
147 RemappedPanoImage<ImageType, AlphaType>*
149  unsigned int imgNr, vigra::Rect2D outputROI,
150  AppBase::ProgressDisplay* progress)
151 {
152  typedef typename ImageType::value_type PixelType;
153 
154  //typedef typename vigra::NumericTraits<PixelType>::RealPromote RPixelType;
155  // typedef typename vigra::BasicImage<RPixelType> RImportImageType;
156  typedef typename vigra::BasicImage<float> FlatImgType;
157 
158  FlatImgType ffImg;
159  AlphaType srcAlpha;
160 
161  // choose image type...
162  const SrcPanoImage & img = pano.getImage(imgNr);
163 
164  vigra::Size2D destSize(opts.getWidth(), opts.getHeight());
165 
167 
168  // load image
169 
170  vigra::ImageImportInfo info(img.getFilename().c_str());
171 
172  int width = info.width();
173  int height = info.height();
174 
175  if (opts.remapUsingGPU) {
176  // Extend image width to multiple of 8 for fast GPU transfers.
177  const int r = width % 8;
178  if (r != 0) width += 8 - r;
179  }
180 
181  ImageType srcImg(width, height);
182  m_remapped->m_ICCProfile = info.getICCProfile();
183 
184  if (info.numExtraBands() > 0) {
185  srcAlpha.resize(width, height);
186  }
187  //int nb = info.numBands() - info.numExtraBands();
188  bool alpha = info.numExtraBands() > 0;
189  std::string type = info.getPixelType();
190 
191  SrcPanoImage src = pano.getSrcImage(imgNr);
192 
193  // import the image
194  progress->setMessage("loading", hugin_utils::stripPath(img.getFilename()));
195 
196  if (alpha) {
198  vigra::destImage(srcAlpha));
199  } else {
200  vigra::importImage(info, vigra::destImage(srcImg));
201  }
202  // check if the image needs to be scaled to 0 .. 1,
203  // this only works for int -> float, since the image
204  // has already been loaded into the output container
205  double maxv = vigra_ext::getMaxValForPixelType(info.getPixelType());
206  if (maxv != vigra_ext::LUTTraits<PixelType>::max()) {
207  double scale = ((double)vigra_ext::LUTTraits<PixelType>::max()) / maxv;
208  //std::cout << "Scaling input image (pixel type: " << info.getPixelType() << " with: " << scale << std::endl;
210  vigra::functor::Arg1()*vigra::functor::Param(scale));
211  }
212 
213  // load flatfield, if needed.
214  if (img.getVigCorrMode() & SrcPanoImage::VIGCORR_FLATFIELD) {
215  // load flatfield image.
216  vigra::ImageImportInfo ffInfo(img.getFlatfieldFilename().c_str());
217  progress->setMessage("flatfield vignetting correction", hugin_utils::stripPath(img.getFilename()));
218  vigra_precondition(( ffInfo.numBands() == 1),
219  "flatfield vignetting correction: "
220  "Only single channel flatfield images are supported\n");
221  ffImg.resize(ffInfo.width(), ffInfo.height());
222  vigra::importImage(ffInfo, vigra::destImage(ffImg));
223  }
224  m_remapped->setAdvancedOptions(SingleImageRemapper<ImageType, AlphaType>::m_advancedOptions);
225  // remap the image
226 
227  remapImage(srcImg, srcAlpha, ffImg,
228  pano.getSrcImage(imgNr), opts,
229  outputROI,
230  *m_remapped,
231  progress);
232  return m_remapped;
233 }
234 
235 
237 template <class FFType, class SrcIter, class SrcAccessor, class DestIter, class DestAccessor>
238 void applyFlatfield(vigra::triple<SrcIter, SrcIter, SrcAccessor> srcImg,
239  vigra::pair<DestIter, DestAccessor> destImg,
240  vigra::ImageImportInfo & ffInfo,
241  double gamma,
242  double gammaMaxVal,
243  bool division,
244  typename vigra::NumericTraits<typename SrcAccessor::value_type>::RealPromote a,
245  typename vigra::NumericTraits<typename SrcAccessor::value_type>::RealPromote b,
246  bool dither)
247 {
248  FFType ffImg(ffInfo.width(), ffInfo.height());
249  vigra::importImage(ffInfo, vigra::destImage(ffImg));
251  destImg, gamma, gammaMaxVal, division, a, b, dither);
252 }
253 
254 
255 }; // namespace
256 }; // namespace
257 
258 #endif // _H
virtual void release(RemappedPanoImage< ImageType, AlphaType > *d)=0
double getMaxValForPixelType(const std::string &v)
Definition: utils.h:89
virtual void release(RemappedPanoImage< ImageType, AlphaType > *d)
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.
virtual RemappedPanoImage< ImageType, AlphaType > * getRemapped(const PanoramaData &pano, const PanoramaOptions &opts, unsigned int imgNr, vigra::Rect2D outputROI, AppBase::ProgressDisplay *progress)=0
create a remapped pano image.
void remapImage(SrcImgType &srcImg, const MaskImgType &srcAlpha, const FlatImgType &srcFlat, const SrcPanoImage &src, const PanoramaOptions &dest, vigra::Rect2D outputRect, RemappedPanoImage< DestImgType, MaskImgType > &remapped, AppBase::ProgressDisplay *progress)
remap a single image
unsigned int getHeight() const
get panorama height
Contains functions to transform whole images.
void flatfieldVigCorrection(vigra::triple< ImgIter, ImgIter, ImgAccessor > srcImg, vigra::pair< FFIter, FFAccessor > ffImg, vigra::pair< DestIter, DestAccessor > destImg, double gamma, double gammaMaxVal, bool division, typename vigra::NumericTraits< typename ImgAccessor::value_type >::RealPromote a, typename vigra::NumericTraits< typename ImgAccessor::value_type >::RealPromote b, bool dither)
vigra::pair< typename ROIImage< Image, Mask >::image_const_traverser, typename ROIImage< Image, Mask >::ImageConstAccessor > srcImage(const ROIImage< Image, Mask > &img)
Definition: ROIImage.h:300
vigra::FRGBImage ImageType
void loadImage(const PanoramaOptions &opts, vigra::ImageImportInfo &info, ImageType &srcImg, AlphaType &srcAlpha)
Definition: ImageRemapper.h:91
void applyFlatfield(vigra::triple< SrcIter, SrcIter, SrcAccessor > srcImg, vigra::pair< DestIter, DestAccessor > destImg, vigra::ImageImportInfo &ffInfo, double gamma, double gammaMaxVal, bool division, typename vigra::NumericTraits< typename SrcAccessor::value_type >::RealPromote a, typename vigra::NumericTraits< typename SrcAccessor::value_type >::RealPromote b, bool dither)
load a flatfield image and apply the correction
void setMessage(const std::string &message, const std::string &filename="")
sets the message to given string
Model for a panorama.
Definition: PanoramaData.h:81
functor to create a remapped image
Definition: ImageRemapper.h:41
virtual const SrcPanoImage & getImage(std::size_t nr) const =0
get a panorama image, counting starts with 0
RemappedPanoImage< ImageType, AlphaType > * m_remapped
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
void importImageAlpha(const ImageImportInfo &import_info, ImageIterator image_iterator, ImageAccessor image_accessor, AlphaIterator alpha_iterator, AlphaAccessor alpha_accessor)
Read the image specified by the given vigra::ImageImportInfo object including its alpha channel...
Definition: impexalpha.hxx:479
unsigned int getWidth() const
std::vector< float > LUT
Definition: ImageRemapper.h:84
void setAdvancedOptions(const HuginBase::Nona::AdvancedOptions advancedOptions)
Definition: ImageRemapper.h:60
HuginBase::Nona::AdvancedOptions m_advancedOptions
Definition: ImageRemapper.h:68
virtual RemappedPanoImage< ImageType, AlphaType > * getRemapped(const PanoramaData &pano, const PanoramaOptions &opts, unsigned int imgNr, vigra::Rect2D outputROI, AppBase::ProgressDisplay *progress)
create a remapped pano image.
std::map< std::string, std::string > AdvancedOptions
static void info(const char *fmt,...)
Definition: svm.cpp:95
virtual SrcPanoImage getSrcImage(unsigned imgNr) const =0
get a complete description of a source image
functor to create a remapped image, loads image from disk
Definition: ImageRemapper.h:75
All variables of a source image.
Definition: SrcPanoImage.h:194
Panorama image options.
std::string stripPath(const std::string &filename)
remove the path of a filename (mainly useful for gui display of filenames)
Definition: utils.cpp:160