Hugin trunk 0.1
Loading...
Searching...
No Matches
CenterHorizontally.cpp
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
26#include "CenterHorizontally.h"
27
28#include <vigra/copyimage.hxx>
32
33
34namespace HuginBase {
35
36
38{
39 vigra::Size2D panoSize(360,180);
40
41 // remap into minature pano.
42 PanoramaOptions opts;
43 opts.setHFOV(360);
45 opts.setWidth(360);
46 opts.setHeight(180);
47
48 // remap image
49 vigra::BImage panoAlpha(panoSize);
51
52 // use selected images.
53 const UIntSet allActiveImgs(panorama.getActiveImages());
54
55 if (allActiveImgs.empty())
56 {
57 // do nothing if there are no images
58 return;
59 }
60
61 //only check unlinked images
63 for (UIntSet::const_iterator it = allActiveImgs.begin(); it!= allActiveImgs.end(); ++it)
64 {
65 const SrcPanoImage & img=panorama.getImage(*it);
66 bool consider=true;
67 if(img.YawisLinked())
68 {
69 for(UIntSet::const_iterator it2=activeImgs.begin(); it2!=activeImgs.end(); ++it2)
70 {
71 if(img.YawisLinkedWith(panorama.getSrcImage(*it2)))
72 {
73 consider=false;
74 break;
75 };
76 };
77 };
78 if(consider)
79 activeImgs.insert(*it);
80 };
81
82 for (UIntSet::iterator it = activeImgs.begin(); it != activeImgs.end(); ++it)
83 {
84 remapped.setPanoImage(panorama.getSrcImage(*it), opts, vigra::Rect2D(0,0,360,180));
85 // calculate alpha channel
86 remapped.calcAlpha();
87 // copy into global alpha channel.
88 vigra::copyImageIf(vigra_ext::applyRect(remapped.boundingBox(),
90 vigra_ext::applyRect(remapped.boundingBox(),
92 vigra_ext::applyRect(remapped.boundingBox(),
93 destImage(panoAlpha)));
94 }
95
96 // get field of view
97 std::vector<int> borders;
98 bool colOccupied = false;
99 for (int h=0; h < 360; h++) {
100 bool curColOccupied = false;
101 for (int v=0; v< 180 && !curColOccupied; v++) {
102 if (panoAlpha(h,v)) {
103 // pixel is valid
104 curColOccupied = true;
105 }
106 }
107 if ((colOccupied && !curColOccupied) ||
109 {
110 // change in position, save point.
111 borders.push_back(h-180);
113 }
114 }
115
116
117 const int lastidx = borders.size() -1;
118 if (lastidx == -1) {
119 // empty pano
120 return;
121 }
122
123 if (colOccupied) {
124 // we have reached the right border, and the pano is still valid
125 if (borders.size() == 1 && borders[0] == -180)
126 {
127 // pano covers full range, nothing to do
128 return;
129 };
130 // shift right fragments by 360 deg
131 // |11 2222| -> | 222211 |
132 std::vector<int> newBorders;
133 newBorders.push_back(borders[lastidx]);
134 for (int i = 0; i < lastidx; i++) {
135 newBorders.push_back(borders[i]+360);
136 }
138 }
139
140 const double dYaw=(borders[0] + borders[lastidx])/2;
141
142 // apply yaw shift, takes also translation parameters into account
143 RotatePanorama(panorama, -dYaw, 0, 0).run();
144}
145
146}
Contains functions to transform whole images.
static void centerHorizontically(PanoramaData &panorama)
struct to hold a image state for stitching
virtual void run()
runs the algorithm.
Model for a panorama.
Panorama image options.
void setHFOV(double h, bool keepView=true)
set the horizontal field of view.
void setProjection(ProjectionFormat f)
set the Projection format and adjust the hfov/vfov if nessecary
void setHeight(unsigned int h)
set panorama height
void setWidth(unsigned int w, bool keepView=true)
set panorama width keep the HFOV, if keepView=true
All variables of a source image.
mainly consists of wrapper around the pano tools library, to assist in ressource management and to pr...
Definition wxcms.cpp:39
std::set< unsigned int > UIntSet
vigra::pair< typename ROIImage< Image, Alpha >::mask_const_traverser, typename ROIImage< Image, Alpha >::MaskConstAccessor > srcMask(const ROIImage< Image, Alpha > &img)
Definition ROIImage.h:347
vigra::triple< typename ROIImage< Image, Alpha >::mask_const_traverser, typename ROIImage< Image, Alpha >::mask_const_traverser, typename ROIImage< Image, Alpha >::MaskConstAccessor > srcMaskRange(const ROIImage< Image, Alpha > &img)
Definition ROIImage.h:335
vigra::triple< ImgIter, ImgIter, ImgAcc > applyRect(vigra::Rect2D &r, vigra::triple< ImgIter, ImgIter, ImgAcc > img)
apply a roi to an image area
Definition ROIImage.h:46
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