8 #ifndef META_OCEAN_CV_SYNTHESIS_MAPPING_H
9 #define META_OCEAN_CV_SYNTHESIS_MAPPING_H
42 inline unsigned int width()
const;
48 inline unsigned int height()
const;
61 virtual void applyMapping(
Frame& frame,
const Frame& mask,
const unsigned int xStart,
const unsigned int xWidth,
const unsigned int yStart,
const unsigned int yHeight,
Worker* worker =
nullptr)
const = 0;
67 explicit inline operator bool()
const;
73 template <
unsigned int tChannels>
80 template <
unsigned int tChannels>
118 template <
unsigned int tChannels>
127 template <
unsigned int tChannels>
178 width_(pixelMapping.width_),
179 height_(pixelMapping.height_),
180 appearanceCostNormalizationInt8_(pixelMapping.appearanceCostNormalizationInt8_),
181 appearanceCostNormalizationInt16_(pixelMapping.appearanceCostNormalizationInt16_),
182 appearanceCostNormalizationInt24_(pixelMapping.appearanceCostNormalizationInt24_),
183 appearanceCostNormalizationInt32_(pixelMapping.appearanceCostNormalizationInt32_),
184 sapatialCostNormalizationInt8_(pixelMapping.sapatialCostNormalizationInt8_),
185 spatialCostNormalizationInt16_(pixelMapping.spatialCostNormalizationInt16_),
186 spatialCostNormalizationInt24_(pixelMapping.spatialCostNormalizationInt24_),
187 spatialCostNormalizationInt32_(pixelMapping.spatialCostNormalizationInt32_)
189 const unsigned int windowHalf = 2u;
203 OCEAN_SUPPRESS_UNUSED_WARNING(windowHalf);
207 width_(pixelMapping.width_),
208 height_(pixelMapping.height_),
209 appearanceCostNormalizationInt8_(pixelMapping.appearanceCostNormalizationInt8_),
210 appearanceCostNormalizationInt16_(pixelMapping.appearanceCostNormalizationInt16_),
211 appearanceCostNormalizationInt24_(pixelMapping.appearanceCostNormalizationInt24_),
212 appearanceCostNormalizationInt32_(pixelMapping.appearanceCostNormalizationInt32_),
213 sapatialCostNormalizationInt8_(pixelMapping.sapatialCostNormalizationInt8_),
214 spatialCostNormalizationInt16_(pixelMapping.spatialCostNormalizationInt16_),
215 spatialCostNormalizationInt24_(pixelMapping.spatialCostNormalizationInt24_),
216 spatialCostNormalizationInt32_(pixelMapping.spatialCostNormalizationInt32_)
218 const unsigned int windowHalf = 2u;
220 ocean_assert(int64_t(appearanceCostNormalizationInt8_) * int64_t(
sqr(2 * windowHalf + 1)) * int64_t(
sqr(width_) +
sqr(height_)) +
221 int64_t(sapatialCostNormalizationInt8_) + int64_t(
sqr(2 * windowHalf + 1)) * int64_t(
sqr(255)) * 26ll < int64_t((
unsigned int)(-1)));
223 ocean_assert(int64_t(appearanceCostNormalizationInt16_) * int64_t(
sqr(2 * windowHalf + 1)) * int64_t(
sqr(width_) +
sqr(height_)) +
224 int64_t(spatialCostNormalizationInt16_) + int64_t(
sqr(2 * windowHalf + 1)) * int64_t(
sqr(255)) * 2ll * 26ll < int64_t((
unsigned int)(-1)));
226 ocean_assert(int64_t(appearanceCostNormalizationInt24_) * int64_t(
sqr(2 * windowHalf + 1)) * int64_t(
sqr(width_) +
sqr(height_)) +
227 int64_t(spatialCostNormalizationInt24_) + int64_t(
sqr(2 * windowHalf + 1)) * int64_t(
sqr(255)) * 3ll * 26ll < int64_t((
unsigned int)(-1)));
229 ocean_assert(int64_t(appearanceCostNormalizationInt32_) * int64_t(
sqr(2 * windowHalf + 1)) * int64_t(
sqr(width_) +
sqr(height_)) +
230 int64_t(spatialCostNormalizationInt32_) + int64_t(
sqr(2 * windowHalf + 1)) * int64_t(
sqr(255)) * 4ll * 26ll < int64_t((
unsigned int)(-1)));
232 OCEAN_SUPPRESS_UNUSED_WARNING(windowHalf);
234 pixelMapping.width_ = 0u;
235 pixelMapping.height_ = 0u;
237 pixelMapping.appearanceCostNormalizationInt8_ = 0u;
238 pixelMapping.appearanceCostNormalizationInt16_ = 0u;
239 pixelMapping.appearanceCostNormalizationInt24_ = 0u;
240 pixelMapping.appearanceCostNormalizationInt32_ = 0u;
242 pixelMapping.sapatialCostNormalizationInt8_ = 0u;
243 pixelMapping.spatialCostNormalizationInt16_ = 0u;
244 pixelMapping.spatialCostNormalizationInt24_ = 0u;
245 pixelMapping.spatialCostNormalizationInt32_ = 0u;
251 appearanceCostNormalizationInt8_(calculateAppearanceCostNormalization<1u>(width, height)),
252 appearanceCostNormalizationInt16_(calculateAppearanceCostNormalization<2u>(width, height)),
253 appearanceCostNormalizationInt24_(calculateAppearanceCostNormalization<3u>(width, height)),
254 appearanceCostNormalizationInt32_(calculateAppearanceCostNormalization<4u>(width, height)),
255 sapatialCostNormalizationInt8_(calculateSpatialCostNormalization<1u>(width, height)),
256 spatialCostNormalizationInt16_(calculateSpatialCostNormalization<2u>(width, height)),
257 spatialCostNormalizationInt24_(calculateSpatialCostNormalization<3u>(width, height)),
258 spatialCostNormalizationInt32_(calculateSpatialCostNormalization<4u>(width, height))
260 const unsigned int windowHalf = 2u;
274 OCEAN_SUPPRESS_UNUSED_WARNING(windowHalf);
292 inline Mapping::operator bool()
const
294 return width_ != 0u && height_ != 0u;
297 template <
unsigned int tChannels>
300 static_assert(oceanFalse<tChannels>(),
"Invalid number of frame channels!");
306 inline unsigned int Mapping::appearanceCostNormalization<1u>()
const
312 inline unsigned int Mapping::appearanceCostNormalization<2u>()
const
318 inline unsigned int Mapping::appearanceCostNormalization<3u>()
const
324 inline unsigned int Mapping::appearanceCostNormalization<4u>()
const
329 template <
unsigned int tChannels>
332 static_assert(oceanFalse<tChannels>(),
"Invalid number of frame channels!");
338 inline unsigned int Mapping::spatialCostNormalization<1u>()
const
344 inline unsigned int Mapping::spatialCostNormalization<2u>()
const
350 inline unsigned int Mapping::spatialCostNormalization<3u>()
const
356 inline unsigned int Mapping::spatialCostNormalization<4u>()
const
361 template <
unsigned int tChannels>
367 unsigned int appearanceNormalization = tChannels * 255u * 255u;
370 if (appearanceNormalization > spatialCost)
372 appearanceNormalization = (appearanceNormalization + spatialCost / 2u) / spatialCost;
378 appearanceNormalization = 1u;
381 return appearanceNormalization;
384 template <
unsigned int tChannels>
390 unsigned int appearanceNormalization = tChannels * 255u * 255u;
393 if (appearanceNormalization > spatialCost)
400 spatialCost = (spatialCost + appearanceNormalization / 2u) / appearanceNormalization;
427 if (
this != &mapping)
430 height_ = mapping.height_;
432 appearanceCostNormalizationInt8_ = mapping.appearanceCostNormalizationInt8_;
433 appearanceCostNormalizationInt16_ = mapping.appearanceCostNormalizationInt16_;
434 appearanceCostNormalizationInt24_ = mapping.appearanceCostNormalizationInt24_;
435 appearanceCostNormalizationInt32_ = mapping.appearanceCostNormalizationInt32_;
437 sapatialCostNormalizationInt8_ = mapping.sapatialCostNormalizationInt8_;
438 spatialCostNormalizationInt16_ = mapping.spatialCostNormalizationInt16_;
439 spatialCostNormalizationInt24_ = mapping.spatialCostNormalizationInt24_;
440 spatialCostNormalizationInt32_ = mapping.spatialCostNormalizationInt32_;
443 mapping.height_ = 0u;
445 mapping.appearanceCostNormalizationInt8_ = 0u;
446 mapping.appearanceCostNormalizationInt16_ = 0u;
447 mapping.appearanceCostNormalizationInt24_ = 0u;
448 mapping.appearanceCostNormalizationInt32_ = 0u;
450 mapping.sapatialCostNormalizationInt8_ = 0u;
451 mapping.spatialCostNormalizationInt16_ = 0u;
452 mapping.spatialCostNormalizationInt24_ = 0u;
453 mapping.spatialCostNormalizationInt32_ = 0u;
This class is the base class for all mappings.
Definition: Mapping.h:35
unsigned int width_
Width of this pixel mapping object in pixel.
Definition: Mapping.h:147
unsigned int spatialCostNormalization() const
Calculates the normalization term for the spatial cost in accordance to the frame dimension of this m...
Definition: Mapping.h:330
unsigned int width() const
Returns the width of this mapping object.
Definition: Mapping.h:282
unsigned int spatialCostNormalizationInt32_
Spatial cost normalization factor for 4 channel 32 bit frames.
Definition: Mapping.h:174
Mapping & operator=(const Mapping &mapping)
Assign operator.
Definition: Mapping.h:407
unsigned int appearanceCostNormalizationInt32_
Appearance cost normalization factor for 4 channel 32 bit frames.
Definition: Mapping.h:162
unsigned int appearanceCostNormalization() const
Calculates the normalization term for the appearance cost in accordance to the frame dimension of thi...
Definition: Mapping.h:298
unsigned int spatialCostNormalizationInt16_
Spatial cost normalization factor for 2 channel 16 bit frames.
Definition: Mapping.h:168
unsigned int height_
Height of this pixel mapping object in pixel.
Definition: Mapping.h:150
unsigned int sapatialCostNormalizationInt8_
Spatial cost normalization factor for 1 channel 8 bit frames.
Definition: Mapping.h:165
unsigned int spatialCostNormalizationInt24_
Spatial cost normalization factor for 3 channel 24 bit frames.
Definition: Mapping.h:171
unsigned int height() const
Returns the height of this mapping object.
Definition: Mapping.h:287
virtual ~Mapping()
Destructs a mapping object.
Definition: Mapping.h:277
unsigned int calculateSpatialCostNormalization(const unsigned int width, const unsigned int height)
Calculates the normalization term for the spatial cost in accordance to a specified frame dimension.
Definition: Mapping.h:385
unsigned int appearanceCostNormalizationInt16_
Appearance cost normalization factor for 2 channel 16 bit frames.
Definition: Mapping.h:156
virtual void applyMapping(Frame &frame, const Frame &mask, const unsigned int xStart, const unsigned int xWidth, const unsigned int yStart, const unsigned int yHeight, Worker *worker=nullptr) const =0
Applies the current mapping for one given frame.
unsigned int appearanceCostNormalizationInt8_
Appearance cost normalization factor for 1 channel 8 bit frames.
Definition: Mapping.h:153
static unsigned int calculateAppearanceCostNormalization(const unsigned int width, const unsigned int height)
Calculates the normalization term for the appearance cost in accordance to a specified frame dimensio...
Definition: Mapping.h:362
unsigned int appearanceCostNormalizationInt24_
Appearance cost normalization factor for 3 channel 24 bit frames.
Definition: Mapping.h:159
Mapping()=default
Creates a new mapping object.
This class implements Ocean's image class.
Definition: Frame.h:1792
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
unsigned int sqr(const char value)
Returns the square value of a given value.
Definition: base/Utilities.h:1029
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15