AliceVision
Photogrammetric Computer Vision Framework
alphaCompositer.hpp
1 // This file is part of the AliceVision project.
2 // Copyright (c) 2020 AliceVision contributors.
3 // This Source Code Form is subject to the terms of the Mozilla Public License,
4 // v. 2.0. If a copy of the MPL was not distributed with this file,
5 // You can obtain one at https://mozilla.org/MPL/2.0/.
6 
7 #pragma once
8 
9 #include "compositer.hpp"
10 
11 namespace aliceVision {
12 
14 {
15  public:
16  AlphaCompositer(size_t outputWidth, size_t outputHeight)
17  : Compositer(outputWidth, outputHeight)
18  {}
19 
20  virtual bool append(aliceVision::image::Image<image::RGBfColor>& color,
23  int offsetX,
24  int offsetY)
25  {
26  offsetX -= _outputRoi.left;
27  offsetY -= _outputRoi.top;
28 
29  for (int i = 0; i < color.height(); i++)
30  {
31  int y = i + offsetY;
32  if (y < 0 || y >= _outputRoi.height)
33  continue;
34 
35  for (int j = 0; j < color.width(); j++)
36  {
37  int x = j + offsetX;
38  if (x < 0 || x >= _outputRoi.width)
39  continue;
40 
41  if (!inputMask(i, j))
42  {
43  continue;
44  }
45 
46  float wc = inputWeights(i, j);
47 
48  _panorama(y, x).r() += wc * color(i, j).r();
49  _panorama(y, x).g() += wc * color(i, j).g();
50  _panorama(y, x).b() += wc * color(i, j).b();
51  _panorama(y, x).a() += wc;
52  }
53  }
54 
55  return true;
56  }
57 
58  virtual bool terminate()
59  {
60  for (int i = 0; i < _panorama.height(); i++)
61  {
62  for (int j = 0; j < _panorama.width(); j++)
63  {
65  image::RGBAfColor c = _panorama(i, j);
66 
67  if (c.a() < 1e-6f)
68  {
69  r.r() = 1.0f;
70  r.g() = 0.0f;
71  r.b() = 0.0f;
72  r.a() = 0.0f;
73  }
74  else
75  {
76  r.r() = c.r() / c.a();
77  r.g() = c.g() / c.a();
78  r.b() = c.b() / c.a();
79  r.a() = 1.0f;
80  }
81 
82  _panorama(i, j) = r;
83  }
84  }
85 
86  return true;
87  }
88 };
89 
90 } // namespace aliceVision
aliceVision::AlphaCompositer
Definition: alphaCompositer.hpp:13
aliceVision::image::Rgba::a
const T & a() const
Get readonly Alpha channel value.
Definition: pixelTypes.hpp:271
aliceVision::image::Rgba
RGBA templated pixel type.
Definition: pixelTypes.hpp:179
aliceVision
Definition: checkerDetector.cpp:32
aliceVision::image::Rgba::g
const T & g() const
Get readonly Green channel value.
Definition: pixelTypes.hpp:251
aliceVision::image::Image
Definition: ImageDescriber_AKAZE_OCV.hpp:21
aliceVision::image::Rgba::r
const T & r() const
Get readonly Red channel value.
Definition: pixelTypes.hpp:241
aliceVision::image::Image::width
int width() const
Retrieve the width of the image.
Definition: Image.hpp:110
aliceVision::image::Image::height
int height() const
Retrieve the height of the image.
Definition: Image.hpp:116
aliceVision::Compositer
Definition: compositer.hpp:17
aliceVision::image::Rgba::b
const T & b() const
Get readonly Blue channel value.
Definition: pixelTypes.hpp:261