Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages
hugin_base/nona/ImageRemapper.h
Go to the documentation of this file.00001 // -*- c-basic-offset: 4 -*- 00027 #ifndef _NONA_IMAGEREMAPPER_H 00028 #define _NONA_IMAGEREMAPPER_H 00029 00030 00031 #include <panodata/PanoramaData.h> 00032 #include <nona/RemappedPanoImage.h> 00033 00034 00035 namespace HuginBase { 00036 namespace Nona { 00037 00038 00040 template <typename ImageType, typename AlphaType> 00041 class SingleImageRemapper 00042 { 00043 00044 public: 00049 virtual RemappedPanoImage<ImageType,AlphaType>* getRemapped(const PanoramaData & pano, 00050 const PanoramaOptions & opts, 00051 unsigned int imgNr, 00052 vigra::Rect2D outputROI, 00053 AppBase::MultiProgressDisplay& progress) = 0; 00054 00055 virtual ~SingleImageRemapper() {}; 00056 00057 00058 public: 00060 virtual void release(RemappedPanoImage<ImageType,AlphaType>* d) = 0; 00061 00062 }; 00063 00064 00066 template <typename ImageType, typename AlphaType> 00067 class FileRemapper : public SingleImageRemapper<ImageType, AlphaType> 00068 { 00069 00070 public: 00071 FileRemapper() 00072 { 00073 m_remapped = 0; 00074 } 00075 00076 virtual ~FileRemapper() {}; 00077 00099 typedef std::vector<float> LUT; 00100 00101 00102 public: 00104 void loadImage(const PanoramaOptions & opts, 00105 vigra::ImageImportInfo & info, ImageType & srcImg, 00106 AlphaType & srcAlpha) 00107 {} 00108 00110 virtual RemappedPanoImage<ImageType, AlphaType>* 00111 getRemapped(const PanoramaData & pano, const PanoramaOptions & opts, 00112 unsigned int imgNr, vigra::Rect2D outputROI, 00113 AppBase::MultiProgressDisplay & progress); 00114 00116 virtual void release(RemappedPanoImage<ImageType,AlphaType>* d) 00117 { delete d; } 00118 00119 00120 protected: 00121 RemappedPanoImage<ImageType,AlphaType> * m_remapped; 00122 00123 }; 00124 00125 00126 00128 template <class FFType, class SrcIter, class SrcAccessor, class DestIter, class DestAccessor> 00129 void applyFlatfield(vigra::triple<SrcIter, SrcIter, SrcAccessor> srcImg, 00130 vigra::pair<DestIter, DestAccessor> destImg, 00131 vigra::ImageImportInfo & ffInfo, 00132 double gamma, 00133 double gammaMaxVal, 00134 bool division, 00135 typename vigra::NumericTraits<typename SrcAccessor::value_type>::RealPromote a, 00136 typename vigra::NumericTraits<typename SrcAccessor::value_type>::RealPromote b, 00137 bool dither); 00138 00139 00140 00141 }; // namespace 00142 }; // namespace 00143 00144 00145 00146 00147 //============================================================================== 00148 // templated implementations 00149 00150 00151 #include <vigra/functorexpression.hxx> 00152 #include <vigra_ext/VignettingCorrection.h> 00153 00154 00155 namespace HuginBase { 00156 namespace Nona { 00157 00158 00159 template <typename ImageType, typename AlphaType> 00160 RemappedPanoImage<ImageType, AlphaType>* 00161 FileRemapper<ImageType,AlphaType>::getRemapped(const PanoramaData & pano, const PanoramaOptions & opts, 00162 unsigned int imgNr, vigra::Rect2D outputROI, 00163 AppBase::MultiProgressDisplay & progress) 00164 { 00165 typedef typename ImageType::value_type PixelType; 00166 00167 //typedef typename vigra::NumericTraits<PixelType>::RealPromote RPixelType; 00168 // typedef typename vigra::BasicImage<RPixelType> RImportImageType; 00169 typedef typename vigra::BasicImage<float> FlatImgType; 00170 00171 FlatImgType ffImg; 00172 AlphaType srcAlpha; 00173 00174 // choose image type... 00175 const SrcPanoImage & img = pano.getImage(imgNr); 00176 00177 vigra::Size2D origSrcSize = img.getSize(); 00178 // DGSW FIXME - Unreferenced 00179 // const PT::VariableMap & srcVars = pano.getImageVariables(imgNr); 00180 // const Lens & lens = pano.getLens(img.getLensNr()); 00181 00182 vigra::Size2D destSize(opts.getWidth(), opts.getHeight()); 00183 00184 m_remapped = new RemappedPanoImage<ImageType, AlphaType>; 00185 00186 // load image 00187 00188 vigra::ImageImportInfo info(img.getFilename().c_str()); 00189 00190 int width = info.width(); 00191 int height = info.height(); 00192 00193 if (opts.remapUsingGPU) { 00194 // Extend image width to multiple of 8 for fast GPU transfers. 00195 const int r = width % 8; 00196 if (r != 0) width += 8 - r; 00197 } 00198 00199 ImageType srcImg(width, height); 00200 m_remapped->m_ICCProfile = info.getICCProfile(); 00201 00202 if (info.numExtraBands() > 0) { 00203 srcAlpha.resize(width, height); 00204 } 00205 //int nb = info.numBands() - info.numExtraBands(); 00206 bool alpha = info.numExtraBands() > 0; 00207 std::string type = info.getPixelType(); 00208 00209 SrcPanoImage src = pano.getSrcImage(imgNr); 00210 00211 // import the image 00212 progress.setMessage(std::string("loading ") + hugin_utils::stripPath(img.getFilename())); 00213 00214 if (alpha) { 00215 vigra::importImageAlpha(info, vigra::destImage(srcImg), 00216 vigra::destImage(srcAlpha)); 00217 } else { 00218 vigra::importImage(info, vigra::destImage(srcImg)); 00219 } 00220 // check if the image needs to be scaled to 0 .. 1, 00221 // this only works for int -> float, since the image 00222 // has already been loaded into the output container 00223 double maxv = vigra_ext::getMaxValForPixelType(info.getPixelType()); 00224 if (maxv != vigra_ext::LUTTraits<PixelType>::max()) { 00225 double scale = ((double)vigra_ext::LUTTraits<PixelType>::max()) / maxv; 00226 //std::cout << "Scaling input image (pixel type: " << info.getPixelType() << " with: " << scale << std::endl; 00227 transformImage(vigra::srcImageRange(srcImg), destImage(srcImg), 00228 vigra::functor::Arg1()*vigra::functor::Param(scale)); 00229 } 00230 00231 // load flatfield, if needed. 00232 if (img.getVigCorrMode() & SrcPanoImage::VIGCORR_FLATFIELD) { 00233 // load flatfield image. 00234 vigra::ImageImportInfo ffInfo(img.getFlatfieldFilename().c_str()); 00235 progress.setMessage(std::string("flatfield vignetting correction ") + hugin_utils::stripPath(img.getFilename())); 00236 vigra_precondition(( ffInfo.numBands() == 1), 00237 "flatfield vignetting correction: " 00238 "Only single channel flatfield images are supported\n"); 00239 ffImg.resize(ffInfo.width(), ffInfo.height()); 00240 vigra::importImage(ffInfo, vigra::destImage(ffImg)); 00241 } 00242 // remap the image 00243 00244 remapImage(srcImg, srcAlpha, ffImg, 00245 pano.getSrcImage(imgNr), opts, 00246 outputROI, 00247 *m_remapped, 00248 progress); 00249 return m_remapped; 00250 } 00251 00252 00254 template <class FFType, class SrcIter, class SrcAccessor, class DestIter, class DestAccessor> 00255 void applyFlatfield(vigra::triple<SrcIter, SrcIter, SrcAccessor> srcImg, 00256 vigra::pair<DestIter, DestAccessor> destImg, 00257 vigra::ImageImportInfo & ffInfo, 00258 double gamma, 00259 double gammaMaxVal, 00260 bool division, 00261 typename vigra::NumericTraits<typename SrcAccessor::value_type>::RealPromote a, 00262 typename vigra::NumericTraits<typename SrcAccessor::value_type>::RealPromote b, 00263 bool dither) 00264 { 00265 FFType ffImg(ffInfo.width(), ffInfo.height()); 00266 vigra::importImage(ffInfo, vigra::destImage(ffImg)); 00267 vigra_ext::flatfieldVigCorrection(srcImg, vigra::srcImage(ffImg), 00268 destImg, gamma, gammaMaxVal, division, a, b, dither); 00269 } 00270 00271 00272 }; // namespace 00273 }; // namespace 00274 00275 #endif // _H
1.3.9.1