Ocean
InitializerCoarserMappingAdaptionAreaConstrainedI1.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_CV_SYNTHESIS_INITIALIZER_COARSER_MAPPING_ADAPTION_AREA_CONSTRAINED_I_1_H
9 #define META_OCEAN_CV_SYNTHESIS_INITIALIZER_COARSER_MAPPING_ADAPTION_AREA_CONSTRAINED_I_1_H
10 
17 
18 namespace Ocean
19 {
20 
21 namespace CV
22 {
23 
24 namespace Synthesis
25 {
26 
27 
28 /**
29  * This initializer creates an initial mapping by the adaption of an already existing mapping of a coarser synthesis layer, further a filter that defines undesired source elements is respected during the initialization.<br>
30  * The initializer supports mapping with integer accuracy.<br>
31  * The coarser mapping is up-sampled and adjusted to the synthesis mask.
32  * @tparam tFactor Defines the dimension increase factor between the synthesis layer and the given coarser layer. A factor of 2 means that the width and height of the synthesis layer is two times larger than the width and height of the given coarser layer, with range [2, infinity)
33  * @see MappingI, LayerI1, InitializerCoarserMappingAdaptionI1.
34  * @ingroup cvsynthesis
35  */
36 template <unsigned int tFactor>
38  virtual public InitializerAreaConstrained,
39  virtual public InitializerI,
40  virtual public InitializerRandomized,
41  virtual public InitializerSubset,
42  virtual public Initializer1
43 {
44  public:
45 
46  /**
47  * Creates a new initializer object.
48  * The provided filter frame must have the same dimension as the given synthesis layer.<br>
49  * @param layer The layer for that the initial mapping has to be provided
50  * @param randomGenerator Random number generator
51  * @param coarserLayer The coarser synthesis layer from the mapping will be adopted
52  * @param filter The filter mask that divides the target region into desired and undesired target content
53  */
54  inline InitializerCoarserMappingAdaptionAreaConstrainedI1(LayerI1& layer, RandomGenerator& randomGenerator, const LayerI1& coarserLayer, const Frame& filter);
55 
56  private:
57 
58  /**
59  * Initializes a subset of the entire mapping area.
60  * @see InitializerSubset::initializeSubset().
61  * @see initializeSubsetChannels().
62  */
63  void initializeSubset(const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int firstRow, const unsigned int numberRows) const override;
64 
65  private:
66 
67  /// Coarser synthesis layer to be used for the mapping adoption.
69 };
70 
71 template <unsigned int tFactor>
73  Initializer(layer),
74  InitializerAreaConstrained(layer, filter),
75  InitializerI(layer),
76  InitializerRandomized(layer, randomGenerator),
77  InitializerSubset(layer),
78  Initializer1(layer),
79  coarserLayerI_(coarserLayer)
80 {
81  // nothing to do here
82 }
83 
84 template <unsigned int tFactor>
85 void InitializerCoarserMappingAdaptionAreaConstrainedI1<tFactor>::initializeSubset(const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int firstRow, const unsigned int numberRows) const
86 {
87  static_assert(tFactor >= 2u, "Invalid factor!");
88 
89  const unsigned int width = layerI_.width();
90  const unsigned int height = layerI_.height();
91 
92  const unsigned int coarserWidth = coarserLayerI_.width();
93  const unsigned int coarserHeight = coarserLayerI_.height();
94 
95  ocean_assert(width / tFactor == coarserWidth);
96  ocean_assert(height / tFactor == coarserHeight);
97 
98  MappingI& mapping = layerI_.mapping();
99  const MappingI& coarserMapping = coarserLayerI_.mapping();
100 
101  RandomGenerator randomGenerator(randomGenerator_);
102 
103  const uint8_t* const maskData = layerI_.mask().template constdata<uint8_t>();
104  const uint8_t* const filterData = filter_.constdata<uint8_t>();
105  const uint8_t* const coarserMaskData = coarserLayerI_.mask().template constdata<uint8_t>();
106 
107  const unsigned int maskStrideElements = layerI_.mask().strideElements();
108  const unsigned int filterStrideElements = filter_.strideElements();
109  const unsigned int coarserMaskStrideElements = coarserLayerI_.mask().strideElements();
110 
111  for (unsigned int y = firstRow; y < firstRow + numberRows; ++y)
112  {
113  const uint8_t* maskRow = maskData + y * maskStrideElements;
114  PixelPosition* positionRow = mapping.row(y);
115 
116  const unsigned int yCoarser = min(y / tFactor, coarserHeight - 1u);
117 
118  const uint8_t* coarserMaskRow = coarserMaskData + yCoarser * coarserMaskStrideElements;
119  const PixelPosition* coarserPositionRow = coarserMapping.row(yCoarser);
120 
121  for (unsigned int x = firstColumn; x < firstColumn + numberColumns; ++x)
122  {
123  if (maskRow[x] != 0xFFu)
124  {
125  const unsigned int xCoarser = min(x / tFactor, coarserWidth - 1u);
126 
127  // if the corresponding coarser layer pixel is a mask pixel
128  if (coarserMaskRow[xCoarser] != 0xFFu)
129  {
130  const PixelPosition& coarserPosition = coarserPositionRow[xCoarser];
131  ocean_assert(coarserPosition.x() < coarserLayerI_.width());
132  ocean_assert(coarserPosition.y() < coarserLayerI_.height());
133 
134  const unsigned int candidateX = (unsigned int)(int(x) + (int(coarserPosition.x()) - int(xCoarser)) * int(tFactor));
135  const unsigned int candidateY = (unsigned int)(int(y) + (int(coarserPosition.y()) - int(yCoarser)) * int(tFactor));
136 
137  ocean_assert(candidateX < width);
138  ocean_assert(candidateY < height);
139 
140  if (maskData[candidateY * maskStrideElements + candidateX] == 0xFFu && filterData[candidateY * filterStrideElements + candidateX] == 0xFFu)
141  {
142  positionRow[x] = CV::PixelPosition(candidateX, candidateY);
143  continue;
144  }
145  }
146 
147  unsigned int candidateX, candidateY;
148  do
149  {
150  candidateX = RandomI::random(randomGenerator, width - 1u);
151  candidateY = RandomI::random(randomGenerator, height - 1u);
152  }
153  while (maskData[candidateY * maskStrideElements + candidateX] != 0xFFu || filterData[candidateY * filterStrideElements + candidateX] != 0xFFu);
154 
155  positionRow[x] = CV::PixelPosition(candidateX, candidateY);
156  }
157  }
158  }
159 }
160 
161 }
162 
163 }
164 
165 }
166 
167 #endif // META_OCEAN_CV_SYNTHESIS_INITIALIZER_COARSER_MAPPING_ADAPTION_AREA_CONSTRAINED_I_1_H
T y() const
Returns the vertical coordinate position of this object.
Definition: PixelPosition.h:470
T x() const
Returns the horizontal coordinate position of this object.
Definition: PixelPosition.h:458
This class is the base class for all initializers that are provided for a single frame only.
Definition: Initializer1.h:29
This class implements a base class for all initializers basing on area constraints.
Definition: InitializerAreaConstrained.h:30
This initializer creates an initial mapping by the adaption of an already existing mapping of a coars...
Definition: InitializerCoarserMappingAdaptionAreaConstrainedI1.h:43
InitializerCoarserMappingAdaptionAreaConstrainedI1(LayerI1 &layer, RandomGenerator &randomGenerator, const LayerI1 &coarserLayer, const Frame &filter)
Creates a new initializer object.
Definition: InitializerCoarserMappingAdaptionAreaConstrainedI1.h:72
const LayerI1 & coarserLayerI_
Coarser synthesis layer to be used for the mapping adoption.
Definition: InitializerCoarserMappingAdaptionAreaConstrainedI1.h:68
void initializeSubset(const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int firstRow, const unsigned int numberRows) const override
Initializes a subset of the entire mapping area.
Definition: InitializerCoarserMappingAdaptionAreaConstrainedI1.h:85
This class implements the base class for all synthesis initializers.
Definition: Initializer.h:34
This class implements the base class for all initializer objects that are applied for mappings with i...
Definition: InitializerI.h:30
This class is the base class for all initializers that mainly initialize the synthesis mapping by a h...
Definition: InitializerRandomized.h:30
This class is the base class for all initializer objects that can separate the initialization process...
Definition: InitializerSubset.h:29
This class implements a single layer for pixel synthesis within one frame and pixel accuracy.
Definition: LayerI1.h:41
This class implements a mapping with integer accuracy.
Definition: MappingI.h:30
const PixelPosition * row(const unsigned int y) const
Returns the pointer to a mapping row.
Definition: MappingI.h:243
This class implements Ocean's image class.
Definition: Frame.h:1792
This class implements a generator for random numbers.
Definition: RandomGenerator.h:42
static unsigned int random(const unsigned int maxValue)
Returns one random integer value with specified maximum value.
PixelPositionT< unsigned int > PixelPosition
Definition of the default PixelPosition object with a data type allowing only positive coordinate val...
Definition: PixelPosition.h:27
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15