Ocean
Loading...
Searching...
No Matches
SynthesisPyramid.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_SYNTHESIS_PYRAMID_H
9#define META_OCEAN_CV_SYNTHESIS_SYNTHESIS_PYRAMID_H
10
12
13#include "ocean/base/Frame.h"
15
18
19namespace Ocean
20{
21
22namespace CV
23{
24
25namespace Synthesis
26{
27
28/**
29 * This class implements the base class for all synthesis pyramids.
30 * @ingroup cvsynthesis
31 */
32class OCEAN_CV_SYNTHESIS_EXPORT SynthesisPyramid
33{
34 public:
35
36 /**
37 * Definition of individual synthesis qualities.
38 */
40 {
41 /// Low synthesis image quality, but very fast.
43 /// Moderate synthesis image quality, with good relation between quality and performance.
45 /// High synthesis image quality, while the performance will be below normal.
47 /// Very high synthesis image quality, while the performance will be slow.
49 };
50
51 /**
52 * Definition of individual initialization techniques.
53 */
55 {
56 /// Appearance mapping initialization, for each mask pixel the best matching target pixel is assigned as initial mapping.
58 /// Random mapping initialization, for each mask pixel a random target pixel is assigned as initial mapping.
60 /// Erosion initialization, shrinking the inpainting mask by an erosion filter in a first step and applying an appearance mapping in a second step.
62 /// Randomized erosion initialization, shrinking the inpainting mask by a randomized erosion filter in a first step and applying an appearance mapping in a second step.
64 /// Contour mapping initialization, for each contour pixel a corresponding second contour pixel is determined an the color values inbetween are interpolated, followed by an appearance mapping.
66 /// Patch initialization, a priority patch-based inpainting approach using the entire source frame as visual input information, applying one iteration.
68 /// Patch initialization, a priority patch-based inpainting approach using the entire source frame as visual input information, applying two iteration.
70 /// Patch initialization, a priority patch-based inpainting approach using a surrounding sub-region as visual input information, applying one iteration.
72 /// Patch initialization, a priority patch-based inpainting approach using a surrounding sub-region as visual input information, applying two iteration.
74 /// Patch initialization, a priority patch-based inpainting approach using the entire source frame as visual input information in combination with an heuristic and propagation appraoch, applying one iteration.
76 /// Patch initialization, a priority patch-based inpainting approach using the entire source frame as visual input information in combination with an heuristic and propagation appraoch, applying two iteration.
77 IT_PATCH_FULL_AREA_HEURISTIC_2
78 };
79
80 public:
81
82 /**
83 * Arranges this synthesis pyramid object for a specified frame and corresponding inpainting mask.
84 * Each pyramid object must be initialized before the actual inpainting can be invoked.
85 * @param frame The frame containing the undesired object to be removed from the frame, must be valid
86 * @param mask The 8 bit mask identifying undesired pixels in the provided frame, pixel values of 0x00 identify undesired pixels, pixel values of 0xFF identify desired pixels, with same frame dimension and pixel origin as the provided frame
87 * @param worker Optional worker object to distribute the computation
88 * @param binomialFilterOnCoarsestLayers True, to applied a binomial filtering on the coarsest pyramid inpainting layer
89 * @param binomialFilterOnFineLayers True, to applied a binomial filter on every other than the coarsest pyramid inpainting layer,
90 * @param filter Optional filter frame identifying valid and invalid source pixels for the image synthesis, if defined must have the same frame dimension and pixel origin as the provided frame
91 * @return True, if succeeded
92 */
93 bool arrange(const Frame& frame, const Frame& mask, Worker* worker = nullptr, const bool binomialFilterOnCoarsestLayers = false, const bool binomialFilterOnFineLayers = false, const Frame& filter = Frame());
94
95 /**
96 * Applies the inpainting on an initialized synthesis pyramid satisfying a specific quality.
97 * @param synthesisQuality The synthesis quality to be reached
98 * @param randomGenerator The random number generator to be used
99 * @param weightFactor Spatial weight impact, with range [0, infinity)
100 * @param borderFactor Weight factor of border pixels, with range [1, infinity)
101 * @param maxSpatialCost Maximal spatial cost, with range [0, 0xFFFFFFFF]
102 * @param worker Optional worker object to distribute the computation
103 * @return True, if succeeded
104 */
105 virtual bool applyInpainting(const SynthesisQuality synthesisQuality, RandomGenerator& randomGenerator, const unsigned int weightFactor = 5u, const unsigned int borderFactor = 25u, const unsigned int maxSpatialCost = (unsigned int)(-1), Worker* worker = nullptr);
106
107 /**
108 * Applies the inpainting on an initialized synthesis pyramid while a specific initialization technique is used on the coarsest pyramid layer.
109 * @param initializationTechnique The initialization technique to be used on the coarsest pyramid layer
110 * @param randomGenerator The random number generator to be used
111 * @param weightFactor Spatial weight impact, with range [0, infinity)
112 * @param borderFactor Weight factor of border pixels, with range [1, infinity)
113 * @param maxSpatialCost Maximal spatial cost, with range [0, 0xFFFFFFFF]
114 * @param optimizationIterations The number of optimization iterations on each pyramid layer (but on the coarsest layer), with range [1, infinity)
115 * @param forced1ChannelLayers The number of (finest) layers on which the synthesis frame is forced to be (by conversion) a 8 bit grayscale frame, with range [0, infinity)
116 * @param skippingLayers The number of (finest) layers on which a skipped optimization will be applied, with range [0, infinity)
117 * @param worker Optional worker object to distribute the computation
118 * @return True, if succeeded
119 */
120 virtual bool applyInpainting(const InitializationTechnique initializationTechnique, RandomGenerator& randomGenerator, const unsigned int weightFactor = 5u, const unsigned int borderFactor = 25u, const unsigned int maxSpatialCost = (unsigned int)(-1), const unsigned int optimizationIterations = 2u, const unsigned int forced1ChannelLayers = 0u, const unsigned int skippingLayers = 0u, Worker* worker = nullptr) = 0;
121
122 /**
123 * Creates the final inpainting result for the finest pyramid layer.
124 * Make sure the given frame has the same frame dimension as the finest pyramid layer, the pixel format may be arbitrary.
125 * @param frame The frame to be finally inpainted, must be valid
126 * @param worker Optional worker object to distribute the computation
127 * @return True, if succeeded
128 */
129 virtual bool createInpaintingResult(Frame& frame, Worker* worker = nullptr) const = 0;
130
131 protected:
132
133 /**
134 * Protected constructor creating a new synthesis pyramid object.
135 * Each synthesis pyramid must be initialized before an inpainting strategy can be invoked.
136 * @see initialize().
137 */
139
140 /**
141 * Virtual Destructor
142 */
143 virtual ~SynthesisPyramid() {}
144
145 /**
146 * Determines the mask bounding boxes for all pyramid layers.
147 * @param worker Optional worker object to distribute the computation
148 */
149 void determineBoundingBoxes(Worker* worker = nullptr);
150
151 /**
152 * Determines the mask bounding boxes for all pyramid layers.
153 * This function is a slow implementation; however, we keep it for debugging purpose.
154 * @param maskPyramid The pyramid of the inpainting masks
155 * @param worker Optional worker object to distribute the computation
156 * @return The resulting individual bounding boxes, one for each valid pyramid layer
157 */
158 PixelBoundingBoxes slowDetermineBoundingBoxes(const FramePyramid& maskPyramid, Worker* worker = nullptr);
159
160 protected:
161
162 /// The frame pyramid holding the frame to be inpainted for individual frame resolutions.
164
165 /// The (frame) pyramid of a mask defining the undesired object for individual frame resolutions.
167
168 /// An optional frame pyramid of an additional filter information identifying valid and invalid source pixels for individual frame resolutions.
170
171 /// The bounding boxes enclosing the undesired mask on each individual layer, with pixel accuracy.
173
174#ifdef OCEAN_DEBUG
175 /// True, if this synthesis pyramid object has been arranged.
177#endif
178};
179
180}
181
182}
183
184}
185
186#endif // META_OCEAN_CV_SYNTHESIS_SYNTHESIS_PYRAMID_H
This class implements a frame pyramid.
Definition FramePyramid.h:37
This class implements the base class for all synthesis pyramids.
Definition SynthesisPyramid.h:33
FramePyramid synthesisMaskPyramid_
The (frame) pyramid of a mask defining the undesired object for individual frame resolutions.
Definition SynthesisPyramid.h:166
virtual bool applyInpainting(const SynthesisQuality synthesisQuality, RandomGenerator &randomGenerator, const unsigned int weightFactor=5u, const unsigned int borderFactor=25u, const unsigned int maxSpatialCost=(unsigned int)(-1), Worker *worker=nullptr)
Applies the inpainting on an initialized synthesis pyramid satisfying a specific quality.
SynthesisQuality
Definition of individual synthesis qualities.
Definition SynthesisPyramid.h:40
@ SQ_HIGH
High synthesis image quality, while the performance will be below normal.
Definition SynthesisPyramid.h:46
@ SQ_VERY_HIGH
Very high synthesis image quality, while the performance will be slow.
Definition SynthesisPyramid.h:48
@ SQ_LOW
Low synthesis image quality, but very fast.
Definition SynthesisPyramid.h:42
@ SQ_MODERATE
Moderate synthesis image quality, with good relation between quality and performance.
Definition SynthesisPyramid.h:44
virtual bool applyInpainting(const InitializationTechnique initializationTechnique, RandomGenerator &randomGenerator, const unsigned int weightFactor=5u, const unsigned int borderFactor=25u, const unsigned int maxSpatialCost=(unsigned int)(-1), const unsigned int optimizationIterations=2u, const unsigned int forced1ChannelLayers=0u, const unsigned int skippingLayers=0u, Worker *worker=nullptr)=0
Applies the inpainting on an initialized synthesis pyramid while a specific initialization technique ...
bool arrange(const Frame &frame, const Frame &mask, Worker *worker=nullptr, const bool binomialFilterOnCoarsestLayers=false, const bool binomialFilterOnFineLayers=false, const Frame &filter=Frame())
Arranges this synthesis pyramid object for a specified frame and corresponding inpainting mask.
PixelBoundingBoxes synthesisBoundingBoxes_
The bounding boxes enclosing the undesired mask on each individual layer, with pixel accuracy.
Definition SynthesisPyramid.h:172
void determineBoundingBoxes(Worker *worker=nullptr)
Determines the mask bounding boxes for all pyramid layers.
FramePyramid synthesisFramePyramid_
The frame pyramid holding the frame to be inpainted for individual frame resolutions.
Definition SynthesisPyramid.h:163
InitializationTechnique
Definition of individual initialization techniques.
Definition SynthesisPyramid.h:55
@ IT_RANDOM
Random mapping initialization, for each mask pixel a random target pixel is assigned as initial mappi...
Definition SynthesisPyramid.h:59
@ IT_CONTOUR_MAPPING
Contour mapping initialization, for each contour pixel a corresponding second contour pixel is determ...
Definition SynthesisPyramid.h:65
@ IT_RANDOM_EROSION
Randomized erosion initialization, shrinking the inpainting mask by a randomized erosion filter in a ...
Definition SynthesisPyramid.h:63
@ IT_APPEARANCE
Appearance mapping initialization, for each mask pixel the best matching target pixel is assigned as ...
Definition SynthesisPyramid.h:57
@ IT_PATCH_FULL_AREA_2
Patch initialization, a priority patch-based inpainting approach using the entire source frame as vis...
Definition SynthesisPyramid.h:69
@ IT_PATCH_FULL_AREA_1
Patch initialization, a priority patch-based inpainting approach using the entire source frame as vis...
Definition SynthesisPyramid.h:67
@ IT_PATCH_SUB_REGION_2
Patch initialization, a priority patch-based inpainting approach using a surrounding sub-region as vi...
Definition SynthesisPyramid.h:73
@ IT_EROSION
Erosion initialization, shrinking the inpainting mask by an erosion filter in a first step and applyi...
Definition SynthesisPyramid.h:61
@ IT_PATCH_FULL_AREA_HEURISTIC_1
Patch initialization, a priority patch-based inpainting approach using the entire source frame as vis...
Definition SynthesisPyramid.h:75
@ IT_PATCH_SUB_REGION_1
Patch initialization, a priority patch-based inpainting approach using a surrounding sub-region as vi...
Definition SynthesisPyramid.h:71
PixelBoundingBoxes slowDetermineBoundingBoxes(const FramePyramid &maskPyramid, Worker *worker=nullptr)
Determines the mask bounding boxes for all pyramid layers.
SynthesisPyramid()
Protected constructor creating a new synthesis pyramid object.
FramePyramid synthesisFilterPyramid_
An optional frame pyramid of an additional filter information identifying valid and invalid source pi...
Definition SynthesisPyramid.h:169
virtual bool createInpaintingResult(Frame &frame, Worker *worker=nullptr) const =0
Creates the final inpainting result for the finest pyramid layer.
bool synthesisHasBeenArranged_
True, if this synthesis pyramid object has been arranged.
Definition SynthesisPyramid.h:176
virtual ~SynthesisPyramid()
Virtual Destructor.
Definition SynthesisPyramid.h:143
This class implements Ocean's image class.
Definition Frame.h:1808
This class implements a generator for random numbers.
Definition RandomGenerator.h:42
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
std::vector< PixelBoundingBox > PixelBoundingBoxes
Definition of a vector holding bounding box objects with only positive coordinate values.
Definition PixelBoundingBox.h:42
The namespace covering the entire Ocean framework.
Definition Accessor.h:15