Ocean
Loading...
Searching...
No Matches
Optimizer4NeighborhoodHighPerformanceI1.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_OPTIMIZER_4_NEIGHBORHOOD_HIGH_PERFORMANCE_I_H
9#define META_OCEAN_CV_SYNTHESIS_OPTIMIZER_4_NEIGHBORHOOD_HIGH_PERFORMANCE_I_H
10
16
18
20
21namespace Ocean
22{
23
24namespace CV
25{
26
27namespace Synthesis
28{
29
30/**
31 * This class implements a high performance mapping optimizer for integer mappings that use one single frame.
32 * @tparam tWeightFactor Spatial weight impact, with range [0, infinity)
33 * @tparam tBorderFactor Weight factor of border pixels, with range [1, infinity)
34 * @tparam tUpdateFrame True, to update the frame pixel whenever a new mapping has been found
35 * @ingroup cvsynthesis
36 */
37template <unsigned int tWeightFactor, unsigned int tBorderFactor, bool tUpdateFrame>
39 virtual public OptimizerI,
40 virtual public OptimizerSubset,
41 virtual public Optimizer1
42{
43 public:
44
45 /**
46 * Creates a new optimizer object.
47 * @param layer The layer to be optimized
48 * @param randomGenerator Random number generator
49 */
51
52 private:
53
54 /**
55 * Optimizes a subset of the synthesis frame.
56 * @see Optimizer1::optimizeSubset().
57 * @see optimizerSubsetChannels().
58 */
59 void optimizeSubset(const unsigned int radii, const unsigned int maxSpatialCost, const unsigned int boundingBoxTop, const unsigned int boundingBoxHeight, const bool downIsMain, const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int rowOffset, const unsigned int firstRow, const unsigned int numberRows, const unsigned int threadIndex) const override;
60
61 /**
62 * Specialization of the default subset optimization function.
63 * The template parameters specified the number of channels the synthesis frame has.<br>
64 * @param radii Number of improvement radii during one optimization iteration for each mapping position
65 * @param maxSpatialCost Maximal spatial cost
66 * @param boundingBoxTop First row of the entire synthesis area
67 * @param boundingBoxHeight Number of rows of the entire synthesis area
68 * @param downIsMain True, if the downwards direction is the main optimization direction (for all subsets with even thread indices)
69 * @param firstColumn First column to be handled in the subset
70 * @param numberColumns Number of columns to be handled in the subset
71 * @param rowOffset Offset within the entire synthesis area (boundingBoxHeight), the subset may be moved by this offset
72 * @param firstRow First row to be handled in the subset
73 * @param numberRows Number of rows to be handled in the subset
74 * @param threadIndex Index of the thread that executes the subset optimization function
75 * @tparam tChannels Number of data channels of the frame
76 * @see optimizerSubset().
77 */
78 template <unsigned int tChannels>
79 void optimizeSubsetChannels(const unsigned int radii, const unsigned int maxSpatialCost, const unsigned int boundingBoxTop, const unsigned int boundingBoxHeight, const bool downIsMain, const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int rowOffset, const unsigned int firstRow, const unsigned int numberRows, const unsigned int threadIndex) const;
80
81 protected:
82
83 /// Specialized layer reference.
85};
86
87template <unsigned int tWeightFactor, unsigned int tBorderFactor, bool tUpdateFrame>
89 Optimizer(layer),
90 OptimizerI(layer),
91 OptimizerSubset(layer, randomGenerator),
92 Optimizer1(layer),
93 layerI1_(layer)
94{
95 // nothing to do here
96}
97
98template <unsigned int tWeightFactor, unsigned int tBorderFactor, bool tUpdateFrame>
99void Optimizer4NeighborhoodHighPerformanceI1<tWeightFactor, tBorderFactor, tUpdateFrame>::optimizeSubset(const unsigned int radii, const unsigned int maxSpatialCost, const unsigned int boundingBoxTop, const unsigned int boundingBoxHeight, const bool downIsMain, const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int rowOffset, const unsigned int firstRow, const unsigned int numberRows, const unsigned int threadIndex) const
100{
101 ocean_assert(layerI1_.frame().numberPlanes() == 1u);
102
103 switch (layerI1_.frame().channels())
104 {
105 case 1u:
106 optimizeSubsetChannels<1u>(radii, maxSpatialCost, boundingBoxTop, boundingBoxHeight, downIsMain, firstColumn, numberColumns, rowOffset, firstRow, numberRows, threadIndex);
107 break;
108
109 case 2u:
110 optimizeSubsetChannels<2u>(radii, maxSpatialCost, boundingBoxTop, boundingBoxHeight, downIsMain, firstColumn, numberColumns, rowOffset, firstRow, numberRows, threadIndex);
111 break;
112
113 case 3u:
114 optimizeSubsetChannels<3u>(radii, maxSpatialCost, boundingBoxTop, boundingBoxHeight, downIsMain, firstColumn, numberColumns, rowOffset, firstRow, numberRows, threadIndex);
115 break;
116
117 case 4u:
118 optimizeSubsetChannels<4u>(radii, maxSpatialCost, boundingBoxTop, boundingBoxHeight, downIsMain, firstColumn, numberColumns, rowOffset, firstRow, numberRows, threadIndex);
119 break;
120
121 default:
122 ocean_assert(false && "Invalid frame type.");
123 }
124}
125
126template <unsigned int tWeightFactor, unsigned int tBorderFactor, bool tUpdateFrame>
127template <unsigned int tChannels>
128void Optimizer4NeighborhoodHighPerformanceI1<tWeightFactor, tBorderFactor, tUpdateFrame>::optimizeSubsetChannels(const unsigned int radii, const unsigned int maxSpatialCost, const unsigned int boundingBoxTop, const unsigned int boundingBoxHeight, const bool downIsMain, const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int rowOffset, const unsigned int firstRow, const unsigned int numberRows, const unsigned int threadIndex) const
129{
130 const unsigned int layerWidth = layerI1_.width();
131 const unsigned int layerHeight = layerI1_.height();
132 ocean_assert(layerWidth != 0 && layerHeight != 0);
133
134 const std::vector<int> searchRadii(calculateSearchRadii(radii, layerWidth, layerHeight));
135
136 Frame& layerFrame = layerI1_.frame();
137 const Frame& layerMask = layerI1_.mask();
138 MappingI1& layerMapping = layerI1_.mapping();
139
140 ocean_assert(FrameType::formatIsGeneric(layerFrame.pixelFormat(), FrameType::DT_UNSIGNED_INTEGER_8, tChannels));
141 ocean_assert(layerFrame.pixelOrigin() == layerMask.pixelOrigin());
142
143 ocean_assert(firstColumn + numberColumns <= layerFrame.width());
144 ocean_assert(firstRow + numberRows <= layerFrame.height());
145
146 RandomGenerator generator(randomGenerator_);
147
148 uint8_t* const layerFrameData = layerFrame.data<uint8_t>();
149 const uint8_t* const layerMaskData = layerMask.constdata<uint8_t>();
150
151 const unsigned int layerFramePaddingElements = layerFrame.paddingElements();
152 const unsigned int layerMaskPaddingElements = layerMask.paddingElements();
153 const unsigned int layerMaskStrideElements = layerMask.strideElements();
154
155#ifdef OCEAN_DEBUG
156 const PixelBoundingBox& debugLayerBoundingBox = layerI1_.boundingBox();
157 ocean_assert(!debugLayerBoundingBox || firstRow >= debugLayerBoundingBox.top());
158 ocean_assert(!debugLayerBoundingBox || firstRow + numberRows <= debugLayerBoundingBox.bottomEnd());
159#endif // OCEAN_DEBUG
160
161 const bool down = (downIsMain && (threadIndex % 2u) == 0u) || (!downIsMain && (threadIndex % 2u) == 1u);
162
163 const unsigned int xStart = firstColumn;
164 const unsigned int yStart = firstRow;
165 const unsigned int xEnd = firstColumn + numberColumns;
166 const unsigned int yEnd = firstRow + numberRows;
167
168 ocean_assert(xEnd - xStart <= layerWidth);
169 ocean_assert(yEnd - yStart <= layerHeight);
170
171 if (down)
172 {
173 // find better positions for each mask pixel (top left to bottom right)
174 for (unsigned int yy = yStart; yy < yEnd; ++yy)
175 {
176 const unsigned int y = modulo(int(yy + rowOffset - boundingBoxTop), int(boundingBoxHeight)) + boundingBoxTop;
177
178 const uint8_t* maskRow = layerMask.constrow<uint8_t>(y) + xStart;
179 PixelPosition* positionRow = layerMapping.row(y) + xStart;
180
181 for (unsigned int x = xStart; x < xEnd; ++x)
182 {
183 bool foundBetter = false;
184
185 ocean_assert(maskRow == layerMask.constpixel<uint8_t>(x, y));
186 if (*maskRow != 0xFF)
187 {
188 unsigned int newPositionX = positionRow->x();
189 unsigned int newPositionY = positionRow->y();
190
191 const uint64_t oldSpatialCost = layerMapping.spatialCost4Neighborhood<tChannels>(x, y, newPositionX, newPositionY, layerMaskData, layerMaskPaddingElements, maxSpatialCost);
192 const uint64_t oldColorCost = layerMapping.appearanceCost5x5<tChannels, tBorderFactor>(x, y, newPositionX, newPositionY, layerFrameData, layerMaskData, layerFramePaddingElements, layerMaskPaddingElements);
193 uint64_t newCost = uint64_t(tWeightFactor) * oldSpatialCost + oldColorCost;
194
195 unsigned int testPositionX, testPositionY;
196
197 // first propagation from left to right
198 ocean_assert(x == 0u || (maskRow - 1) == layerMask.constpixel<uint8_t>(x - 1u, y));
199 if (x > 0u && *(maskRow - 1) != 0xFFu)
200 {
201 ocean_assert(layerMapping.position(x - 1, y));
202 ocean_assert(*(positionRow - 1) == layerMapping.position(x - 1, y));
203
204 // take the position to the left (of the current position)
205 testPositionX = (positionRow - 1)->x() + 1;
206 testPositionY = (positionRow - 1)->y();
207
208 if (testPositionX < layerWidth && layerMaskData[testPositionY * layerMaskStrideElements + testPositionX] == 0xFF)
209 {
210 // the structure cost is 0 due to the neighbor condition
211 ocean_assert_accuracy(layerMapping.spatialCost4Neighborhood<tChannels>(x, y, testPositionX, testPositionY, layerMaskData, layerMaskPaddingElements, maxSpatialCost) == 0u);
212
213 const uint64_t testCost = layerMapping.appearanceCost5x5<tChannels, tBorderFactor>(x, y, testPositionX, testPositionY, layerFrameData, layerMaskData, layerFramePaddingElements, layerMaskPaddingElements);
214
215 if (testCost < newCost)
216 {
217 newPositionX = testPositionX;
218 newPositionY = testPositionY;
219 newCost = testCost;
220 foundBetter = true;
221 }
222 }
223
224 // second propagation from top to bottom
225 ocean_assert(y == 0u || (maskRow - layerMaskStrideElements) == layerMask.constpixel<uint8_t>(x, y - 1u));
226 if (y > 0u && *(maskRow - layerMaskStrideElements) != 0xFFu
227 // test only if the mapping of the left position does not match (shifted) to the mapping of the top position
228 && (positionRow - 1)->northEast() != *(positionRow - layerWidth))
229 {
230 ocean_assert(layerMapping.position(x, y - 1));
231 ocean_assert(*(positionRow - layerWidth) == layerMapping.position(x, y - 1));
232
233 // take the next position to the top (of the current position)
234 testPositionX = (positionRow - layerWidth)->x();
235 testPositionY = (positionRow - layerWidth)->y() + 1;
236
237 if (testPositionY < layerHeight && layerMaskData[testPositionY * layerMaskStrideElements + testPositionX] == 0xFF)
238 {
239 // the structure cost is 0 due to the neighbor condition
240 ocean_assert_accuracy(layerMapping.spatialCost4Neighborhood<tChannels>(x, y, testPositionX, testPositionY, layerMaskData, layerMaskPaddingElements, maxSpatialCost) == 0u);
241
242 const uint64_t testCost = layerMapping.appearanceCost5x5<tChannels, tBorderFactor>(x, y, testPositionX, testPositionY, layerFrameData, layerMaskData, layerFramePaddingElements, layerMaskPaddingElements);
243
244 if (testCost < newCost)
245 {
246 newPositionX = testPositionX;
247 newPositionY = testPositionY;
248 newCost = testCost;
249 foundBetter = true;
250 }
251 }
252 }
253 }
254 else
255 {
256 // second propagation from top to bottom
257 ocean_assert(y == 0u || (maskRow - layerMaskStrideElements) == layerMask.constpixel<uint8_t>(x, y - 1u));
258 if (y > 0u && *(maskRow - layerMaskStrideElements) != 0xFFu)
259 {
260 ocean_assert(layerMapping.position(x, y - 1));
261 ocean_assert(*(positionRow - layerWidth) == layerMapping.position(x, y - 1));
262
263 // take the next position to the top (of the current position)
264 testPositionX = (positionRow - layerWidth)->x();
265 testPositionY = (positionRow - layerWidth)->y() + 1;
266
267 if (testPositionY < layerHeight && layerMaskData[testPositionY * layerMaskStrideElements + testPositionX] == 0xFF)
268 {
269 // the structure cost is 0 due to the neighbor condition
270 ocean_assert_accuracy(layerMapping.spatialCost4Neighborhood<tChannels>(x, y, testPositionX, testPositionY, layerMaskData, layerMaskPaddingElements, maxSpatialCost) == 0u);
271
272 const uint64_t testCost = layerMapping.appearanceCost5x5<tChannels, tBorderFactor>(x, y, testPositionX, testPositionY, layerFrameData, layerMaskData, layerFramePaddingElements, layerMaskPaddingElements);
273
274 if (testCost < newCost)
275 {
276 newPositionX = testPositionX;
277 newPositionY = testPositionY;
278 newCost = testCost;
279 foundBetter = true;
280 }
281 }
282 }
283 }
284
285 // find a better position of the current mask pixel
286 for (unsigned int n = 0; n < radii; ++n)
287 {
288 ocean_assert(newPositionX != (unsigned int)(-1) && newPositionY != (unsigned int)(-1));
289
290 testPositionX = newPositionX + RandomI::random(generator, -searchRadii[n], searchRadii[n]);
291 testPositionY = newPositionY + RandomI::random(generator, -searchRadii[n], searchRadii[n]);
292
293 // the test position must lie inside the mask
294 if ((testPositionX == newPositionX && testPositionY == newPositionY)
295 || testPositionX >= layerWidth || testPositionY >= layerHeight
296 || layerMaskData[testPositionY * layerMaskStrideElements + testPositionX] != 0xFF)
297 {
298 continue;
299 }
300
301 const uint64_t testSpatialCost = layerMapping.spatialCost4Neighborhood<tChannels>(x, y, testPositionX, testPositionY, layerMaskData, layerMaskPaddingElements, maxSpatialCost);
302 const uint64_t testColorCost = layerMapping.appearanceCost5x5<tChannels, tBorderFactor>(x, y, testPositionX, testPositionY, layerFrameData, layerMaskData, layerFramePaddingElements, layerMaskPaddingElements);
303
304 const uint64_t testCost = uint64_t(tWeightFactor) * testSpatialCost + testColorCost;
305
306 if (testCost < newCost)
307 {
308 newPositionX = testPositionX;
309 newPositionY = testPositionY;
310 newCost = testCost;
311 foundBetter = true;
312 }
313 }
314
315 if (tUpdateFrame && foundBetter)
316 {
317 ocean_assert(layerMaskData[y * layerWidth + x] != 0xFF);
318 ocean_assert(layerMaskData[newPositionY * layerMaskStrideElements + newPositionX] == 0xFF);
319
320 positionRow->setPosition(newPositionX, newPositionY);
321
322 CV::CVUtilities::copyPixel<tChannels>(layerFrameData, layerFrameData, x, y, newPositionX, newPositionY, layerWidth, layerWidth, layerFramePaddingElements, layerFramePaddingElements);
323 }
324 }
325
326 ++maskRow;
327 ++positionRow;
328 }
329 }
330 }
331 else // up
332 {
333 // find better positions for each mask pixel (bottom right to top left)
334 for (unsigned int yy = yEnd - 1u; yy != yStart - 1u; --yy)
335 {
336 const unsigned int y = modulo(int(yy + rowOffset - boundingBoxTop), int(boundingBoxHeight)) + boundingBoxTop;
337
338 const uint8_t* maskRow = layerMask.constrow<uint8_t>(y) + xEnd - 1u;
339 PixelPosition* positionRow = layerMapping.row(y) + xEnd - 1u;
340
341 for (unsigned int x = xEnd - 1u; x != xStart - 1u; --x)
342 {
343 bool foundBetter = false;
344
345 ocean_assert(maskRow == layerMask.constpixel<uint8_t>(x, y));
346 if (*maskRow != 0xFF)
347 {
348 unsigned int newPositionX = positionRow->x();
349 unsigned int newPositionY = positionRow->y();
350
351 const uint64_t oldSpatialCost = layerMapping.spatialCost4Neighborhood<tChannels>(x, y, newPositionX, newPositionY, layerMaskData, layerMaskPaddingElements, maxSpatialCost);
352 const uint64_t oldColorCost = layerMapping.appearanceCost5x5<tChannels, tBorderFactor>(x, y, newPositionX, newPositionY, layerFrameData, layerMaskData, layerFramePaddingElements, layerMaskPaddingElements);
353 uint64_t newCost = uint64_t(tWeightFactor) * oldSpatialCost + oldColorCost;
354
355 unsigned int testPositionX, testPositionY;
356
357 // first propagation from right to left
358 ocean_assert(x == layerWidth - 1u || (maskRow + 1) == layerMask.constpixel<uint8_t>(x + 1u, y));
359 if (x < layerWidth - 1u && *(maskRow + 1) != 0xFFu)
360 {
361 ocean_assert(layerMapping.position(x + 1, y));
362 ocean_assert(*(positionRow + 1) == layerMapping.position(x + 1, y));
363
364 // take the position to the right (of the current position)
365 testPositionX = (positionRow + 1)->x() - 1;
366 testPositionY = (positionRow + 1)->y();
367
368 if (testPositionX != (unsigned int)(-1) && layerMaskData[testPositionY * layerWidth + testPositionX] == 0xFF)
369 {
370 // the structure cost is 0 due to the neighbor condition
371 ocean_assert_accuracy(layerMapping.spatialCost4Neighborhood<tChannels>(x, y, testPositionX, testPositionY, layerMaskData, layerMaskPaddingElements, maxSpatialCost) == 0u);
372
373 const uint64_t testCost = layerMapping.appearanceCost5x5<tChannels, tBorderFactor>(x, y, testPositionX, testPositionY, layerFrameData, layerMaskData, layerFramePaddingElements, layerMaskPaddingElements);
374
375 if (testCost < newCost)
376 {
377 newPositionX = testPositionX;
378 newPositionY = testPositionY;
379 newCost = testCost;
380 foundBetter = true;
381 }
382 }
383
384 // second propagation from bottom to top
385 ocean_assert(y == layerHeight - 1u || (maskRow + layerMaskStrideElements) == layerMask.constpixel<uint8_t>(x, y + 1u));
386 if (y < layerHeight - 1u && *(maskRow + layerMaskStrideElements) != 0xFFu
387 // test only if the mapping of the right position does not match (shifted) to the mapping of the bottom position
388 && (positionRow + 1)->southWest() != *(positionRow + layerWidth))
389 {
390 ocean_assert(layerMapping.position(x, y + 1));
391 ocean_assert(*(positionRow + layerWidth) == layerMapping.position(x, y + 1));
392
393 // take the next position towards the bottom (of the current position)
394 testPositionX = (positionRow + layerWidth)->x();
395 testPositionY = (positionRow + layerWidth)->y() - 1;
396
397 if (testPositionY != (unsigned int)(-1) && layerMaskData[testPositionY * layerWidth + testPositionX] == 0xFF)
398 {
399 // the structure cost is 0 due to the neighbor condition
400 ocean_assert_accuracy(layerMapping.spatialCost4Neighborhood<tChannels>(x, y, testPositionX, testPositionY, layerMaskData, layerMaskPaddingElements, maxSpatialCost) == 0u);
401
402 const uint64_t testCost = layerMapping.appearanceCost5x5<tChannels, tBorderFactor>(x, y, testPositionX, testPositionY, layerFrameData, layerMaskData, layerFramePaddingElements, layerMaskPaddingElements);
403
404 if (testCost < newCost)
405 {
406 newPositionX = testPositionX;
407 newPositionY = testPositionY;
408 newCost = testCost;
409 foundBetter = true;
410 }
411 }
412 }
413 }
414 else
415 {
416 // second propagation from bottom to top
417 ocean_assert(y == layerHeight - 1u || (maskRow + layerMaskStrideElements) == layerMask.constpixel<uint8_t>(x, y + 1u));
418 if (y < layerHeight - 1u && *(maskRow + layerMaskStrideElements) != 0xFFu)
419 {
420 ocean_assert(layerMapping.position(x, y + 1));
421 ocean_assert(*(positionRow + layerWidth) == layerMapping.position(x, y + 1));
422
423 // take the next position towards the bottom (of the current position)
424 testPositionX = (positionRow + layerWidth)->x();
425 testPositionY = (positionRow + layerWidth)->y() - 1;
426
427 if (testPositionY != (unsigned int)(-1) && layerMaskData[testPositionY * layerWidth + testPositionX] == 0xFF)
428 {
429 // the structure cost is 0 due to the neighbor condition
430 ocean_assert_accuracy(layerMapping.spatialCost4Neighborhood<tChannels>(x, y, testPositionX, testPositionY, layerMaskData, layerMaskPaddingElements, maxSpatialCost) == 0u);
431
432 const uint64_t testCost = layerMapping.appearanceCost5x5<tChannels, tBorderFactor>(x, y, testPositionX, testPositionY, layerFrameData, layerMaskData, layerFramePaddingElements, layerMaskPaddingElements);
433
434 if (testCost < newCost)
435 {
436 newPositionX = testPositionX;
437 newPositionY = testPositionY;
438 newCost = testCost;
439 foundBetter = true;
440 }
441 }
442 }
443 }
444
445 // find a better position of the current mask pixel
446 for (unsigned int n = 0; n < radii; ++n)
447 {
448 ocean_assert(newPositionX != (unsigned int)(-1) && newPositionY != (unsigned int)(-1));
449
450 testPositionX = newPositionX + RandomI::random(generator, -searchRadii[n], searchRadii[n]);
451 testPositionY = newPositionY + RandomI::random(generator, -searchRadii[n], searchRadii[n]);
452
453 if ((testPositionX == newPositionX && testPositionY == newPositionY)
454 || testPositionX >= layerWidth || testPositionY >= layerHeight
455 || layerMaskData[testPositionY * layerWidth + testPositionX] != 0xFF)
456 {
457 continue;
458 }
459
460 const uint64_t testSpatialCost = layerMapping.spatialCost4Neighborhood<tChannels>(x, y, testPositionX, testPositionY, layerMaskData, layerMaskPaddingElements, maxSpatialCost);
461 const uint64_t testColorCost = layerMapping.appearanceCost5x5<tChannels, tBorderFactor>(x, y, testPositionX, testPositionY, layerFrameData, layerMaskData, layerFramePaddingElements, layerMaskPaddingElements);
462 const uint64_t testCost = uint64_t(tWeightFactor) * testSpatialCost + testColorCost;
463
464 if (testCost < newCost)
465 {
466 newPositionX = testPositionX;
467 newPositionY = testPositionY;
468 newCost = testCost;
469 foundBetter = true;
470 }
471 }
472
473 if (tUpdateFrame && foundBetter)
474 {
475 ocean_assert(layerMaskData[y * layerWidth + x] != 0xFF);
476 ocean_assert(layerMaskData[newPositionY * layerWidth + newPositionX] == 0xFF);
477
478 positionRow->setPosition(newPositionX, newPositionY);
479
480 CV::CVUtilities::copyPixel<tChannels>(layerFrameData, layerFrameData, x, y, newPositionX, newPositionY, layerWidth, layerWidth, layerFramePaddingElements, layerFramePaddingElements);
481 }
482 }
483
484 --maskRow;
485 --positionRow;
486 }
487 }
488 }
489}
490
491}
492
493}
494
495}
496
497#endif // META_OCEAN_CV_SYNTHESIS_OPTIMIZER_4_NEIGHBORHOOD_HIGH_PERFORMANCE_I_H
T bottomEnd() const
Returns the bottom (excluding) pixel position of this bounding box.
Definition PixelBoundingBox.h:451
T top() const
Returns the top (including) pixel position of this bounding box.
Definition PixelBoundingBox.h:423
This class implements a single layer for pixel synthesis within one frame and pixel accuracy.
Definition LayerI1.h:41
This class implements the pixel mapping between source and target frames.
Definition MappingI1.h:49
unsigned int spatialCost4Neighborhood(const unsigned int xTarget, const unsigned int yTarget, const unsigned int xSource, const unsigned int ySource, const uint8_t *targetMask, const unsigned int targetMaskPaddingElements, const unsigned int maxCost) const
Calculates the smallest/cheapest spatial cost for a given point in a four-neighborhood and normalizes...
Definition MappingI1.h:212
unsigned int appearanceCost5x5(const unsigned int xTarget, const unsigned int yTarget, const unsigned int xSource, const unsigned int ySource, const uint8_t *frame, const uint8_t *mask, const unsigned int framePaddingElements, const unsigned int maskPaddingElements) const
Calculates the appearance cost for a given point in a given frame.
Definition MappingI1.h:666
const PixelPosition * row(const unsigned int y) const
Returns the pointer to a mapping row.
Definition MappingI.h:243
const PixelPosition & position(const unsigned int x, const unsigned int y) const
Returns the mapping for a given position.
Definition MappingI.h:215
This class implements the base class for all synthesis optimizers that use one single frame.
Definition Optimizer1.h:28
This class implements a high performance mapping optimizer for integer mappings that use one single f...
Definition Optimizer4NeighborhoodHighPerformanceI1.h:42
LayerI1 & layerI1_
Specialized layer reference.
Definition Optimizer4NeighborhoodHighPerformanceI1.h:84
Optimizer4NeighborhoodHighPerformanceI1(LayerI1 &layer, RandomGenerator &randomGenerator)
Creates a new optimizer object.
Definition Optimizer4NeighborhoodHighPerformanceI1.h:88
void optimizeSubsetChannels(const unsigned int radii, const unsigned int maxSpatialCost, const unsigned int boundingBoxTop, const unsigned int boundingBoxHeight, const bool downIsMain, const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int rowOffset, const unsigned int firstRow, const unsigned int numberRows, const unsigned int threadIndex) const
Specialization of the default subset optimization function.
Definition Optimizer4NeighborhoodHighPerformanceI1.h:128
void optimizeSubset(const unsigned int radii, const unsigned int maxSpatialCost, const unsigned int boundingBoxTop, const unsigned int boundingBoxHeight, const bool downIsMain, const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int rowOffset, const unsigned int firstRow, const unsigned int numberRows, const unsigned int threadIndex) const override
Optimizes a subset of the synthesis frame.
Definition Optimizer4NeighborhoodHighPerformanceI1.h:99
This class is the base class for all synthesis optimizers.
Definition Optimizer.h:30
This class is the base class for all optimizers that use a mapping with integer accuracy.
Definition OptimizerI.h:29
This class is the base class for all optimizers that are able to optimize seperate subsets of the syn...
Definition OptimizerSubset.h:30
This class implements Ocean's image class.
Definition Frame.h:1808
unsigned int strideElements(const unsigned int planeIndex=0u) const
Returns the number of elements within one row, including optional padding at the end of a row for a s...
Definition Frame.h:4141
const T * constdata(const unsigned int planeIndex=0u) const
Returns a pointer to the read-only pixel data of a specific plane.
Definition Frame.h:4251
T * data(const unsigned int planeIndex=0u)
Returns a pointer to the pixel data of a specific plane.
Definition Frame.h:4242
const T * constpixel(const unsigned int x, const unsigned int y, const unsigned int planeIndex=0u) const
Returns the pointer to the constant data of a specific pixel.
Definition Frame.h:4333
const T * constrow(const unsigned int y, const unsigned int planeIndex=0u) const
Returns the pointer to the constant data of a specific row.
Definition Frame.h:4276
unsigned int paddingElements(const unsigned int planeIndex=0u) const
Returns the optional number of padding elements at the end of each row for a specific plane.
Definition Frame.h:4125
unsigned int width() const
Returns the width of the frame format in pixel.
Definition Frame.h:3170
PixelOrigin pixelOrigin() const
Returns the pixel origin of the frame.
Definition Frame.h:3215
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition Frame.h:3180
@ DT_UNSIGNED_INTEGER_8
Unsigned 8 bit integer data type (uint8_t).
Definition Frame.h:41
unsigned int height() const
Returns the height of the frame in pixel.
Definition Frame.h:3175
static bool formatIsGeneric(const PixelFormat pixelFormat, const DataType dataType, const uint32_t channels, const uint32_t planes=1u, const uint32_t widthMultiple=1u, const uint32_t heightMultiple=1u)
Checks whether a given pixel format is a specific layout regarding data channels and data type.
Definition Frame.h:3435
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.
T modulo(const T &value, const T &ring)
Returns the modulo value of a given parameter within a ring allowing positive and negative parameters...
Definition base/Utilities.h:948
The namespace covering the entire Ocean framework.
Definition Accessor.h:15