8 #ifndef META_OCEAN_CV_SYNTHESIS_INITIALIZER_APPEARANCE_MAPPING_AREA_CONSTRAINED_I_1_H
9 #define META_OCEAN_CV_SYNTHESIS_INITIALIZER_APPEARANCE_MAPPING_AREA_CONSTRAINED_I_1_H
38 template <
unsigned int tPatchSize,
unsigned int tIterations>
65 void initializeSubset(
const unsigned int firstColumn,
const unsigned int numberColumns,
const unsigned int firstRow,
const unsigned int numberRows)
const override;
76 template <
unsigned int tChannels>
77 void initializeSubsetChannels(
const unsigned int firstColumn,
const unsigned int numberColumns,
const unsigned int firstRow,
const unsigned int numberRows)
const;
80 template <
unsigned int tPatchSize,
unsigned int tIterations>
93 template <
unsigned int tPatchSize,
unsigned int tIterations>
96 static_assert(tPatchSize == 1u,
"Invalid patch size!");
98 ocean_assert(layerI_.frame().numberPlanes() == 1u);
101 switch (layerI_.frame().channels())
104 initializeSubsetChannels<1u>(firstColumn, numberColumns, firstRow, numberRows);
108 initializeSubsetChannels<2u>(firstColumn, numberColumns, firstRow, numberRows);
112 initializeSubsetChannels<3u>(firstColumn, numberColumns, firstRow, numberRows);
116 initializeSubsetChannels<4u>(firstColumn, numberColumns, firstRow, numberRows);
120 ocean_assert(
false &&
"Invalid frame type.");
124 template <
unsigned int tPatchSize,
unsigned int tIterations>
125 template <
unsigned int tChannels>
128 static_assert(tPatchSize == 1u,
"Invalid patch size!");
129 static_assert(tChannels >= 1u,
"Invalid channel number!");
131 const unsigned int tPatchSize_2 = tPatchSize / 2u;
133 const unsigned int width = layerI_.width();
134 const unsigned int height = layerI_.height();
136 MappingI& layerMapping = layerI_.mapping();
138 const Frame& frame = layerI_.frame();
139 const Frame& mask = layerI_.mask();
144 ocean_assert(frame.
width() == width);
145 ocean_assert(frame.
height() == height);
152 const uint8_t*
const frameData = frame.
constdata<uint8_t>();
153 const uint8_t*
const maskData = mask.
constdata<uint8_t>();
154 const uint8_t*
const filterData = filter_.template constdata<uint8_t>();
159 const unsigned int filterStrideElements = filter_.strideElements();
163 ocean_assert(!debugLayerBoundingBox || firstColumn >= debugLayerBoundingBox.
left());
164 ocean_assert(!debugLayerBoundingBox || firstColumn + numberColumns <= debugLayerBoundingBox.
rightEnd());
165 ocean_assert(!debugLayerBoundingBox || firstRow >= debugLayerBoundingBox.
top());
166 ocean_assert(!debugLayerBoundingBox || firstRow + numberRows <= debugLayerBoundingBox.
bottomEnd());
169 ocean_assert(firstColumn + numberColumns <= width);
170 ocean_assert(firstRow + numberRows <= height);
172 for (
unsigned int y = firstRow; y < firstRow + numberRows; ++y)
174 const uint8_t* maskRow = maskData + y * maskStrideElements + firstColumn;
177 for (
unsigned int x = firstColumn; x < firstColumn + numberColumns; ++x)
179 if (*maskRow++ != 0xFF)
181 unsigned int bestX, bestY;
185 bestX =
RandomI::random(randomGenerator, tPatchSize_2, width - tPatchSize_2 - 1u);
186 bestY =
RandomI::random(randomGenerator, tPatchSize_2, height - tPatchSize_2 - 1u);
188 while (maskData[bestY * maskStrideElements + bestX] != 0xFF || filterData[bestY * filterStrideElements + bestX] != 0xFF);
190 unsigned int bestSSD = CV::SumSquareDifferences::patch8BitPerChannel<tChannels, tPatchSize>(frameData, frameData, width, width, x, y, bestX, bestY, framePaddingElements, framePaddingElements);
192 for (
unsigned int n = 1u; n < tIterations; ++n)
194 const unsigned int candidateX =
RandomI::random(randomGenerator, tPatchSize_2, width - tPatchSize_2 - 1u);
195 const unsigned int candidateY =
RandomI::random(randomGenerator, tPatchSize_2, height - tPatchSize_2 - 1u);
197 if (maskData[candidateY * maskStrideElements + candidateX] != 0xFF || filterData[candidateY * filterStrideElements + candidateX] != 0xFF)
202 const unsigned int candidateSSD = CV::SumSquareDifferences::patch8BitPerChannel<tChannels, tPatchSize>(frameData, frameData, width, width, x, y, candidateX, candidateY, framePaddingElements, framePaddingElements);
204 if (candidateSSD < bestSSD)
208 bestSSD = candidateSSD;
T left() const
Returns the left (including) pixel position of this bounding box.
Definition: PixelBoundingBox.h:416
T rightEnd() const
Returns the right (excluding) pixel position of this bounding box.
Definition: PixelBoundingBox.h:437
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
void setPosition(const T &x, const T &y)
Sets the two coordinate values of this object.
Definition: PixelPosition.h:482
This class is the base class for all initializers that are provided for a single frame only.
Definition: Initializer1.h:29
This class implements an initializer that uses appearance constraints for the mapping and further res...
Definition: InitializerAppearanceMappingAreaConstrainedI1.h:46
InitializerAppearanceMappingAreaConstrainedI1(LayerI1 &layer, RandomGenerator &randomGenerator, const Frame &filter)
Creates a new initializer object.
Definition: InitializerAppearanceMappingAreaConstrainedI1.h:81
void initializeSubsetChannels(const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int firstRow, const unsigned int numberRows) const
This function is the specialization of the default initializeSubset() function.
Definition: InitializerAppearanceMappingAreaConstrainedI1.h:126
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: InitializerAppearanceMappingAreaConstrainedI1.h:94
This class implements the abstract base class for all appearance initializers.
Definition: InitializerAppearanceMapping.h:28
This class implements a base class for all initializers basing on area constraints.
Definition: InitializerAreaConstrained.h:30
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
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:4058
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:4168
bool isValid() const
Returns whether this frame is valid.
Definition: Frame.h:4448
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:4042
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition: Frame.h:30
unsigned int width() const
Returns the width of the frame format in pixel.
Definition: Frame.h:3143
uint32_t numberPlanes() const
Returns the number of planes of the pixel format of this frame.
Definition: Frame.h:3183
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition: Frame.h:3153
@ 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:3148
DataType dataType() const
Returns the data type of the pixel format of this frame.
Definition: Frame.h:3163
bool isFrameTypeCompatible(const FrameType &frameType, const bool allowDifferentPixelOrigins) const
Returns whether this frame type is compatible with a given frame type.
Definition: Frame.h:3203
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.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15