Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
wxImageCache.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
27 #include "wxImageCache.h"
28 #include "vigra_ext/utils.h"
29 
30 wxImage imageCacheEntry2wxImage(ImageCache::EntryPtr e)
31 {
32  if (e->imageFloat->size().area() > 0)
33  {
34  // for float images we need to apply the mapping as selected by the user
35  // in the preferences
36  const int mapping = wxConfigBase::Get()->Read(wxT("/ImageCache/Mapping"), HUGIN_IMGCACHE_MAPPING_FLOAT);
37  // find average and variance
38  vigra::RGBToGrayAccessor<vigra::RGBValue<float> > ga;
39  vigra::FindAverageAndVariance<float> mean; // init functor
40  vigra::inspectImage(srcImageRange(*(e->imageFloat), ga), mean);
41  // create temporary image with remapped tone scale
42  vigra::BRGBImage mappedImg(e->imageFloat->size());
43  // scale image to (mean - 3 * std deviation) - (mean + 3 * std deviation),
44  vigra_ext::applyMapping(srcImageRange(*(e->imageFloat)), destImage(mappedImg), std::max(mean.average() - 3 * sqrt(mean.variance()), 1e-6f), mean.average() + 3 * sqrt(mean.variance()), mapping);
45  // convert to wxImage
46  wxImage mappedwxImg(mappedImg.width(), mappedImg.height(), (unsigned char *)mappedImg.data(), true);
47  return mappedwxImg.Copy();
48  }
49  else
50  {
51  ImageCacheRGB8Ptr img = e->get8BitImage();
52  if (img)
53  {
54  return wxImage(img->width(), img->height(), (unsigned char *)img->data(), true);
55  }
56  else
57  {
58  // invalid wxImage
59  return wxImage();
60  };
61  };
62 }
63 
HuginBase::ImageCache::ImageCacheRGB8Ptr ImageCacheRGB8Ptr
Definition: wxImageCache.h:33
void applyMapping(vigra::triple< SrcIterator, SrcIterator, SrcAccessor > img, vigra::pair< DestIterator, DestAccessor > dest, T min, T max, int mapping)
Definition: utils.h:685
functions to manage ROI&#39;s
wxImage imageCacheEntry2wxImage(ImageCache::EntryPtr e)
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
static T max(T x, T y)
Definition: svm.cpp:65
#define HUGIN_IMGCACHE_MAPPING_FLOAT