8 #ifndef META_OCEAN_CV_SYNTHESIS_INITIALIZER_COARSER_MAPPING_ADAPTION_SPATIAL_COST_MASK_I_1_H
9 #define META_OCEAN_CV_SYNTHESIS_INITIALIZER_COARSER_MAPPING_ADAPTION_SPATIAL_COST_MASK_I_1_H
36 template <
unsigned int tFactor, const
unsigned int tNeighborhood>
66 void initializeSubset(
const unsigned int firstColumn,
const unsigned int numberColumns,
const unsigned int firstRow,
const unsigned int numberRows)
const override;
80 template <
unsigned int tFactor, const
unsigned int tNeighborhood>
87 coarserLayerI_(coarserLayer),
89 coarserCostMask_(
FrameType(coarserLayer.width(), coarserLayer.height(),
FrameType::FORMAT_Y8, coarserLayer.frame().pixelOrigin()))
91 static_assert(tNeighborhood == 1u || tNeighborhood == 9u,
"Invalid neighborhood!");
94 template <
unsigned int tFactor, const
unsigned int tNeighborhood>
97 static_assert(tNeighborhood == 1u || tNeighborhood == 9u,
"Invalid neighborhood!");
109 template <
unsigned int tFactor, const
unsigned int tNeighborhood>
112 static_assert(tFactor == 2u,
"Invalid factor!");
113 static_assert(tNeighborhood == 1u || tNeighborhood == 9u,
"Invalid neighborhood!");
115 const unsigned int width = layerI_.width();
116 const unsigned int height = layerI_.height();
118 const unsigned int coarserWidth = coarserLayerI_.width();
119 const unsigned int coarserHeight = coarserLayerI_.height();
121 ocean_assert(width / tFactor == coarserWidth);
122 ocean_assert(height / tFactor == coarserHeight);
124 MappingI& mapping = layerI_.mapping();
125 const MappingI& coarserMapping = coarserLayerI_.mapping();
129 const uint8_t*
const mask = layerI_.mask().template constdata<uint8_t>();
130 const uint8_t*
const coarserMask = coarserLayerI_.mask().template constdata<uint8_t>();
131 uint8_t*
const costMask = costMask_.data<uint8_t>();
132 const uint8_t*
const coarserCostMask = coarserCostMask_.constdata<uint8_t>();
134 const unsigned int maskStrideElements = layerI_.mask().strideElements();
135 const unsigned int coarserMaskStrideElements = coarserLayerI_.mask().strideElements();
136 const unsigned int costMaskStrideElements = costMask_.strideElements();
137 const unsigned int coarserCostMaskStrideElements = coarserCostMask_.strideElements();
139 for (
unsigned int y = firstRow; y < firstRow + numberRows; ++y)
141 const uint8_t* maskRow = mask + y * maskStrideElements;
144 const unsigned int yCoarser = min(y / tFactor, coarserHeight - 1u);
146 const uint8_t* coarserMaskRow = coarserMask + yCoarser * coarserMaskStrideElements;
149 for (
unsigned int x = firstColumn; x < firstColumn + numberColumns; ++x)
151 if (maskRow[x] != 0xFFu)
153 const unsigned int xCoarser = min(x / tFactor, coarserWidth - 1u);
156 if (coarserMaskRow[xCoarser] != 0xFFu)
158 const PixelPosition& coarserPosition = coarserPositionRow[xCoarser];
159 ocean_assert(coarserPosition.
x() < coarserLayerI_.width());
160 ocean_assert(coarserPosition.
y() < coarserLayerI_.height());
162 const unsigned int candidateX = (
unsigned int)(
int(x) + (int(coarserPosition.
x()) - int(xCoarser)) *
int(tFactor));
163 const unsigned int candidateY = (
unsigned int)(
int(y) + (int(coarserPosition.
y()) - int(yCoarser)) *
int(tFactor));
165 ocean_assert(candidateX < width);
166 ocean_assert(candidateY < height);
168 if (mask[candidateY * maskStrideElements + candidateX] == 0xFFu)
172 if constexpr (tNeighborhood == 1u)
174 if (coarserCostMask[yCoarser * coarserCostMaskStrideElements + xCoarser] == 0x80u)
176 costMask[y * costMaskStrideElements + x] = 0xFFu;
181 if (xCoarser - 1u < coarserWidth - 2u && yCoarser - 1u < coarserHeight - 2u)
183 const uint8_t*
const coarserCostData = coarserCostMask + (yCoarser - 1u) * coarserCostMaskStrideElements + (xCoarser - 1u);
185 if (coarserCostData[0] == 0x80u && coarserCostData[1] == 0x80u && coarserCostData[2] == 0x80u
186 && coarserCostData[coarserCostMaskStrideElements + 0u] == 0x80u && coarserCostData[coarserCostMaskStrideElements + 1u] == 0x80u && coarserCostData[coarserCostMaskStrideElements + 2u] == 0x80u
187 && coarserCostData[2u * coarserCostMaskStrideElements + 0u] == 0x80u && coarserCostData[2u * coarserCostMaskStrideElements + 1u] == 0x80u && coarserCostData[2u * coarserCostMaskStrideElements + 2u] == 0x80u)
189 costMask[y * costMaskStrideElements + x] = 0xFFu;
194 bool zeroBlock =
true;
196 for (
int xxCoarser =
int(xCoarser) - 1; zeroBlock && xxCoarser <= int(xCoarser) + 1; ++xxCoarser)
198 for (
int yyCoarser =
int(yCoarser) - 1; zeroBlock && yyCoarser <= int(yCoarser) + 1; ++yyCoarser)
200 if ((
unsigned int)(xxCoarser) < coarserWidth && (
unsigned int)(yyCoarser) < coarserHeight)
202 if (coarserCostMask[(
unsigned int)(yyCoarser) * coarserCostMaskStrideElements + (
unsigned int)(xxCoarser)] != 0x80u)
212 costMask[y * costMaskStrideElements + x] = 0xFFu;
222 unsigned int candidateX, candidateY;
228 while (mask[candidateY * maskStrideElements + candidateX] != 0xFFu);
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 initializer creates an initial mapping by the adaption of an already existing mapping of a coars...
Definition: InitializerCoarserMappingAdaptionSpatialCostMaskI1.h:42
const LayerI1 & coarserLayerI_
Coarser synthesis layer from that the mapping will be adapted.
Definition: InitializerCoarserMappingAdaptionSpatialCostMaskI1.h:71
bool invoke(Worker *worker=nullptr) const override
Invokes the initialization process.
Definition: InitializerCoarserMappingAdaptionSpatialCostMaskI1.h:95
InitializerCoarserMappingAdaptionSpatialCostMaskI1(LayerI1 &layer, RandomGenerator &randomGenerator, const LayerI1 &coarserLayer, Frame &costMask)
Creates a new initializer object.
Definition: InitializerCoarserMappingAdaptionSpatialCostMaskI1.h:81
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: InitializerCoarserMappingAdaptionSpatialCostMaskI1.h:110
Frame & costMask_
Resulting cost map for the finer layer.
Definition: InitializerCoarserMappingAdaptionSpatialCostMaskI1.h:74
Frame coarserCostMask_
Temporal spatial cost mask for the coarser layer.
Definition: InitializerCoarserMappingAdaptionSpatialCostMaskI1.h:77
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
bool invoke(Worker *worker=nullptr) const override
Invokes the initialization process.
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
@ ACM_COPY_REMOVE_PADDING_LAYOUT
Same as CM_COPY_REMOVE_PADDING_LAYOUT.
Definition: Frame.h:1818
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition: Frame.h:30
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.
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
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