Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PreviewColorPickerTool.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
9 /*
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This software is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public
21  * License along with this software. If not, see
22  * <http://www.gnu.org/licenses/>.
23  *
24  */
25 
26 #ifdef _WIN32
27 #include "wx/msw/wrapwin.h"
28 #endif
30 #include <wx/platform.h>
31 #include "GLPreviewFrame.h"
32 #include <huginapp/ImageCache.h>
35 #include <vigra/copyimage.hxx>
36 #include <vigra/inspectimage.hxx>
37 
39 #define ColorPickerSize 10
40 
41 // we want to be notified if the user click into the panorama
43 {
45  helper->SetStatusMessage(_("Click on a area which should be neutral gray / white in the final panorama."));
46 };
47 
48 // The user click, get the current position and update white balance
50 {
51  if ( e.LeftDown() && helper->IsMouseOverPano())
52  {
54  if(m_count>0 && m_red!=0 && m_blue!=0)
55  {
57  }
58  else
59  {
60  wxBell();
61  };
62  };
63 };
64 
66 {
67  m_red=0;
68  m_blue=0;
69  m_count=0;
71  HuginBase::UIntSet activeImages=pano->getActiveImages();
72  if(!activeImages.empty())
73  {
74  for(HuginBase::UIntSet::iterator it=activeImages.begin();it!=activeImages.end();++it)
75  {
76  //check if point is inside the image, check also all 4 corners of rectangle
78  trans.createTransform(pano->getImage(*it),pano->getOptions());
79  double x;
80  double y;
81  if(trans.transformImgCoord(x,y,pos.x,pos.y))
82  {
83  vigra::Point2D imagePos(x,y);
84  if(pano->getImage(*it).isInside(imagePos) &&
85  pano->getImage(*it).isInside(imagePos + vigra::Point2D(-ColorPickerSize,-ColorPickerSize)) &&
86  pano->getImage(*it).isInside(imagePos + vigra::Point2D(-ColorPickerSize, ColorPickerSize)) &&
87  pano->getImage(*it).isInside(imagePos + vigra::Point2D( ColorPickerSize,-ColorPickerSize)) &&
88  pano->getImage(*it).isInside(imagePos + vigra::Point2D( ColorPickerSize, ColorPickerSize))
89  )
90  {
91  CalcCorrectionForImage(*it,imagePos);
92  };
93  };
94  };
95  };
96  if(m_count>0)
97  {
100  };
101 };
102 
103 void PreviewColorPickerTool::CalcCorrectionForImage(unsigned int i,vigra::Point2D pos)
104 {
106  HuginBase::ImageCache::ImageCacheRGB8Ptr cacheImage8 = HuginBase::ImageCache::getInstance().getImage(img.getFilename())->get8BitImage();
107 
108  //copy only region to be inspected
109  vigra::BRGBImage tempImage(2*ColorPickerSize,2*ColorPickerSize);
110  vigra::copyImage(vigra::make_triple((*cacheImage8).upperLeft() + pos + vigra::Point2D(-ColorPickerSize,-ColorPickerSize),
111  (*cacheImage8).upperLeft() + pos + vigra::Point2D( ColorPickerSize, ColorPickerSize),
112  vigra::BRGBImage::Accessor()),
113  destImage(tempImage) );
114 
115  //now apply photometric corrections
118  {
119  // select exposure and response curve for LDR output
120  std::vector<double> outLut;
121  vigra_ext::EMoR::createEMoRLUT(helper->GetPanoramaPtr()->getImage(0).getEMoRParams(), outLut);
123  invResponse.setOutput(1.0/pow(2.0,helper->GetPanoramaPtr()->getOptions().outputExposureValue), outLut,
124  255.0);
125  }
126  else
127  {
128  invResponse.setHDROutput(true,1.0/pow(2.0,helper->GetPanoramaPtr()->getOptions().outputExposureValue));
129  }
130  vigra::DRGBImage floatTemp(tempImage.size());
131  vigra_ext::transformImageSpatial(srcImageRange(tempImage), destImage(floatTemp), invResponse, vigra::Diff2D(pos.x-ColorPickerSize,pos.y-ColorPickerSize));
132 
133  //calculate average
134  vigra::FindAverage<vigra::DRGBImage::PixelType> average;
135  vigra::inspectImage(srcImageRange(floatTemp), average);
136  //range check
137  vigra::RGBValue<double> RGBaverage=average.average();
138  if(RGBaverage[0]>2 && RGBaverage[0]<253 &&
139  RGBaverage[1]>2 && RGBaverage[1]<253 &&
140  RGBaverage[2]>2 && RGBaverage[2]<253)
141  {
142  m_red+=RGBaverage[0]/RGBaverage[1];
143  m_blue+=RGBaverage[2]/RGBaverage[1];
144  m_count++;
145  };
146 };
void transformImageSpatial(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor sa, DestImageIterator dest_upperleft, DestAccessor da, Functor const &f, vigra::Diff2D ul)
Definition: utils.h:725
implementation of huginApp Class
hugin_utils::FDiff2D GetMousePanoPosition()
Definition: ToolHelper.cpp:295
void CalcCorrectionForImage(unsigned int i, vigra::Point2D pos)
radiometric transformation, includes exposure, vignetting and white balance
HuginBase::Panorama * GetPanoramaPtr()
Definition: ToolHelper.cpp:310
void enforceMonotonicity(LUT &lut)
enforce monotonicity of an array (mostly used for lookup tables)
Definition: lut.h:87
void NotifyMe(Event event, Tool *tool)
Definition: ToolHelper.cpp:315
bool isInside(vigra::Point2D p, bool ignoreMasks=false) const
check if a coordinate is inside the source image
static ImageCache & getInstance()
get the global ImageCache object
Definition: ImageCache.cpp:294
std::set< unsigned int > UIntSet
Definition: PanoramaData.h:51
void Activate()
Switch on a tool.
ToolHelper * helper
The PreviewToolHelper that uses the same preview window and panorama as the tool should.
Definition: Tool.h:102
Model for a panorama.
Definition: Panorama.h:152
bool IsMouseOverPano()
Definition: ToolHelper.h:136
std::shared_ptr< vigra::BRGBImage > ImageCacheRGB8Ptr
use reference counted pointers
Definition: ImageCache.h:57
float pow(float a, double b)
Definition: utils.h:181
void MouseButtonEvent(wxMouseEvent &e)
process mouse button events
vigra::pair< typename ROIImage< Image, Alpha >::image_traverser, typename ROIImage< Image, Alpha >::ImageAccessor > destImage(ROIImage< Image, Alpha > &img)
Definition: ROIImage.h:324
Contains functions to transform whole images.
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
UIntSet getActiveImages() const
get active images
Definition: Panorama.cpp:1585
void createEMoRLUT(const std::vector< float > &params, VECTOR &lut)
Definition: emor.h:44
#define ColorPickerSize
half size of color picker window size
EntryPtr getImage(const std::string &filename)
get a image.
Definition: ImageCache.cpp:419
bool transformImgCoord(double &x_dest, double &y_dest, double x_src, double y_src) const
like transform, but return image coordinates, not cartesian coordinates
const PanoramaOptions & getOptions() const
returns the options for this panorama
Definition: Panorama.h:481
Holds transformations for Image -&gt; Pano and the other way.
void SetStatusMessage(wxString message)
Definition: ToolHelper.cpp:409
void copyImage(SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor src_acc, DestImageIterator dest_upperleft, DestAccessor dest_acc)
Definition: openmp_vigra.h:305
void CalcCorrection(hugin_utils::FDiff2D pos)
const SrcPanoImage & getImage(std::size_t nr) const
get a panorama image, counting starts with 0
Definition: Panorama.h:211
All variables of a source image.
Definition: SrcPanoImage.h:194
void UpdateGlobalWhiteBalance(double redFactor, double blueFactor)
updates the global white balance
GLPreviewFrame * GetPreviewFrame()
Definition: ToolHelper.h:139
void createTransform(const vigra::Diff2D &srcSize, VariableMap srcVars, Lens::LensProjectionFormat srcProj, const vigra::Diff2D &destSize, PanoramaOptions::ProjectionFormat destProj, const std::vector< double > &destProjParam, double destHFOV, const vigra::Diff2D &origSrcSize)
initialize pano-&gt;image transformation