AliceVision
Photogrammetric Computer Vision Framework
seams.hpp
1 #pragma once
2 
3 // This file is part of the AliceVision project.
4 // Copyright (c) 2020 AliceVision contributors.
5 // This Source Code Form is subject to the terms of the Mozilla Public License,
6 // v. 2.0. If a copy of the MPL was not distributed with this file,
7 // You can obtain one at https://mozilla.org/MPL/2.0/.
8 
9 #include <aliceVision/types.hpp>
10 #include <aliceVision/image/Image.hpp>
11 
12 #include "cachedImage.hpp"
13 #include "graphcut.hpp"
14 
15 namespace aliceVision {
16 
17 void drawBorders(aliceVision::image::Image<image::RGBAfColor>& inout, aliceVision::image::Image<unsigned char>& mask, int offset_x, int offset_y);
18 
19 void drawSeams(aliceVision::image::Image<image::RGBAfColor>& inout, aliceVision::image::Image<IndexT>& labels, int offset_x, int offset_y);
20 
21 bool getMaskFromLabels(aliceVision::image::Image<float>& mask, image::Image<IndexT>& labels, IndexT index, int offset_x, int offset_y);
22 
23 class WTASeams
24 {
25  public:
26  WTASeams(size_t outputWidth, size_t outputHeight)
27  : _weights(outputWidth, outputHeight, true, 0.0f),
28  _labels(outputWidth, outputHeight, true, UndefinedIndexT),
29  _panoramaWidth(outputWidth),
30  _panoramaHeight(outputHeight)
31  {}
32 
33  virtual ~WTASeams() = default;
34 
35  bool append(const aliceVision::image::Image<unsigned char>& inputMask,
36  const aliceVision::image::Image<float>& inputWeights,
37  IndexT currentIndex,
38  size_t offset_x,
39  size_t offset_y);
40 
41  bool appendWithLoop(const aliceVision::image::Image<unsigned char>& inputMask,
42  const aliceVision::image::Image<float>& inputWeights,
43  IndexT currentIndex,
44  size_t offset_x,
45  size_t offset_y);
46 
47  image::Image<IndexT>& getLabels() { return _labels; }
48 
49  private:
50  image::Image<float> _weights;
51  image::Image<IndexT> _labels;
52 
53  int _panoramaWidth;
54  int _panoramaHeight;
55 };
56 
58 {
59  public:
60  HierarchicalGraphcutSeams(size_t outputWidth, size_t outputHeight, size_t countLevels)
61  : _outputWidth(outputWidth),
62  _outputHeight(outputHeight),
63  _countLevels(countLevels)
64  {}
65 
66  virtual ~HierarchicalGraphcutSeams() = default;
67 
68  bool initialize(const image::Image<IndexT>& labels);
69 
70  virtual bool append(const aliceVision::image::Image<image::RGBfColor>& input,
72  IndexT currentIndex,
73  size_t offset_x,
74  size_t offset_y);
75 
76  bool process();
77 
78  image::Image<IndexT>& getLabels() { return _graphcuts[0].getLabels(); }
79 
80  private:
81  std::vector<GraphcutSeams> _graphcuts;
82 
83  size_t _countLevels;
84  size_t _outputWidth;
85  size_t _outputHeight;
86 };
87 
88 } // namespace aliceVision
aliceVision
Definition: checkerDetector.cpp:32
aliceVision::image::Image
Definition: ImageDescriber_AKAZE_OCV.hpp:21
aliceVision::HierarchicalGraphcutSeams
Definition: seams.hpp:57
aliceVision::WTASeams
Definition: seams.hpp:23