Hugin trunk 0.1
Loading...
Searching...
No Matches
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
34
35namespace HuginBase {
36namespace Nona {
37
38
40 template <typename ImageType, typename AlphaType>
71
72
74 template <typename ImageType, typename AlphaType>
75 class FileRemapper : public SingleImageRemapper<ImageType, AlphaType>
76 {
77
78 public:
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,
94 {}
95
98 getRemapped(const PanoramaData & pano, const PanoramaOptions & opts,
99 unsigned int imgNr, vigra::Rect2D outputROI,
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
142namespace HuginBase {
143namespace Nona {
144
145
146template <typename ImageType, typename AlphaType>
147RemappedPanoImage<ImageType, AlphaType>*
149 unsigned int imgNr, vigra::Rect2D outputROI,
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
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) {
197 vigra::importImageAlpha(info, vigra::destImage(srcImg),
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());
207 double scale = ((double)vigra_ext::LUTTraits<PixelType>::max()) / maxv;
208 //std::cout << "Scaling input image (pixel type: " << info.getPixelType() << " with: " << scale << std::endl;
209 transformImage(vigra::srcImageRange(srcImg), destImage(srcImg),
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 }
225 // remap the image
226
228 pano.getSrcImage(imgNr), opts,
229 outputROI,
230 *m_remapped,
231 progress);
232 return m_remapped;
233}
234
235
237template <class FFType, class SrcIter, class SrcAccessor, class DestIter, class DestAccessor>
238void 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
Contains functions to transform whole images.
@ VIGCORR_FLATFIELD
flatfield correction
functor to create a remapped image, loads image from disk
std::vector< float > LUT
void loadImage(const PanoramaOptions &opts, vigra::ImageImportInfo &info, ImageType &srcImg, AlphaType &srcAlpha)
virtual void release(RemappedPanoImage< ImageType, AlphaType > *d)
RemappedPanoImage< ImageType, AlphaType > * m_remapped
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.
struct to hold a image state for stitching
functor to create a remapped image
HuginBase::Nona::AdvancedOptions m_advancedOptions
void setAdvancedOptions(const HuginBase::Nona::AdvancedOptions advancedOptions)
virtual void release(RemappedPanoImage< ImageType, AlphaType > *d)=0
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.
Model for a panorama.
virtual SrcPanoImage getSrcImage(unsigned imgNr) const =0
get a complete description of a source image
virtual const SrcPanoImage & getImage(std::size_t nr) const =0
get a panorama image, counting starts with 0
Panorama image options.
unsigned int getWidth() const
unsigned int getHeight() const
get panorama height
All variables of a source image.
class AlphaIterator class AlphaAccessor inline void importImageAlpha(const ImageImportInfo &import_info, ImageIterator image_iterator, ImageAccessor image_accessor, AlphaIterator alpha_iterator, AlphaAccessor alpha_accessor)
vigra::FRGBImage ImageType
std::map< std::string, std::string > AdvancedOptions
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 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
mainly consists of wrapper around the pano tools library, to assist in ressource management and to pr...
Definition wxcms.cpp:39
std::string stripPath(const std::string &filename)
remove the path of a filename (mainly useful for gui display of filenames)
Definition utils.cpp:160
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)
double getMaxValForPixelType(const std::string &v)
Definition utils.h:89
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