8 #ifndef META_OCEAN_CV_SEGMENTATION_FRAME_FILTER_BLUR_H
9 #define META_OCEAN_CV_SEGMENTATION_FRAME_FILTER_BLUR_H
26 namespace Segmentation
42 class OCEAN_CV_SEGMENTATION_EXPORT
Comfort
76 template <
unsigned int tChannels>
77 static bool blurMaskRegions8BitPerChannel(uint8_t* image,
const uint8_t* mask,
const unsigned int width,
const unsigned int height,
const unsigned int imagePaddingElements,
const unsigned int maskPaddingElements,
const unsigned int blurBorder = 5u,
RandomGenerator* randomGenerator =
nullptr);
80 template <
unsigned int tChannels>
83 static_assert(tChannels >= 1u,
"Invalid channel number!");
85 ocean_assert(image !=
nullptr);
86 ocean_assert(mask !=
nullptr);
87 ocean_assert(width >= 1u && height >= 1u);
88 ocean_assert(blurBorder == 0u || blurBorder % 2u == 1u);
107 ocean_assert(maskBlock.size() > 0 && maskBlock.size() <= width * height);
111 uint64_t sumColors[tChannels] = {};
115 for (
unsigned int y = 0u; pixels != maskBlock.size() && y < separation.
height(); ++y)
117 const uint32_t*
const rowSepartion = separation.
constrow<uint32_t>(y);
118 const uint8_t*
const rowImage = imageFrame.
constrow<uint8_t>(y);
120 for (
unsigned int x = 0u; pixels != maskBlock.size() && x < separation.
width(); ++x)
122 if (rowSepartion[x] == maskBlock.id())
124 for (
unsigned int n = 0u; n < tChannels; ++n)
126 sumColors[n] += rowImage[x * tChannels + n];
136 ocean_assert(pixels != 0);
137 ocean_assert(pixelBoundingBox.
isValid());
144 uint8_t averageColors[tChannels];
146 for (
unsigned int n = 0u; n < tChannels; ++n)
148 averageColors[n] = uint8_t((sumColors[n] + (pixels / 2)) / pixels);
150 if (randomGenerator !=
nullptr)
152 averageColors[n] = uint8_t(
minmax(0,
int(averageColors[n]) +
RandomI::random(*randomGenerator, -10, 10), 255));
156 for (
unsigned int y = pixelBoundingBox.
top(); y < pixelBoundingBox.
bottomEnd(); ++y)
158 const uint32_t*
const rowSepartion = separation.
constrow<uint32_t>(y);
159 uint8_t*
const rowImage = imageFrame.
row<uint8_t>(y);
161 for (
unsigned int x = pixelBoundingBox.
left(); x < pixelBoundingBox.
rightEnd(); ++x)
163 if (rowSepartion[x] == maskBlock.id())
165 for (
unsigned int n = 0u; n < tChannels; ++n)
167 rowImage[x * tChannels + n] = averageColors[n];
173 pixelBoundingBoxes.push_back(pixelBoundingBox);
176 if (blurBorder != 0u && blurBorder % 2u != 0u)
181 ocean_assert(maskBlocks.size() == pixelBoundingBoxes.size());
185 for (
size_t n = 0; n < maskBlocks.size(); ++n)
193 Frame blurredSubFrame;
196 ocean_assert(
false &&
"This should never happen!");
202 for (
unsigned int iteration = 1u; iteration < blurBorder; ++iteration)
204 borderPixels.clear();
206 for (
unsigned int y = 0u; y < blendMask.
height(); ++y)
208 const uint8_t* row = blendMask.
constrow<uint8_t>(y);
210 for (
unsigned int x = 0u; x < blendMask.
width(); ++x)
214 if ((x > 0u && *(row - 1) != 0xFFu) || (x < blendMask.
width() - 1u && *(row + 1) != 0xFFu) || (y > 0u && *(row - blendMask.
width()) != 0xFFu) || (y < blendMask.
height() - 1u && *(row + blendMask.
width()) != 0xFFu))
216 borderPixels.emplace_back(x, y);
224 const uint8_t targetColor = uint8_t((iteration * 255u) / blurBorder);
226 uint8_t* blendMaskData = blendMask.
data<uint8_t>();
230 blendMaskData[borderPixel.index(blendMask.
width())] = targetColor;
static bool filter(const Frame &source, Frame &target, const unsigned int filterSize, Worker *worker=nullptr, ReusableMemory *reusableMemory=nullptr)
Applies a Gaussian blur filter to a given source image and copies the resulting filter results to a g...
T left() const
Returns the left (including) pixel position of this bounding box.
Definition: PixelBoundingBox.h:416
unsigned int width() const
Returns the width (the number of horizontal including pixels) of this bounding box.
Definition: PixelBoundingBox.h:482
T rightEnd() const
Returns the right (excluding) pixel position of this bounding box.
Definition: PixelBoundingBox.h:437
bool isValid() const
Returns whether this bounding box covers a valid pixel area.
Definition: PixelBoundingBox.h:577
T bottomEnd() const
Returns the bottom (excluding) pixel position of this bounding box.
Definition: PixelBoundingBox.h:451
PixelBoundingBoxT< T > extended(const unsigned int pixels, const T minLeft, const T minTop, const T maxRight, const T maxBottom) const
Returns a new bounding box by extending this bounding box with a given number of pixel in each direct...
Definition: PixelBoundingBox.h:558
T top() const
Returns the top (including) pixel position of this bounding box.
Definition: PixelBoundingBox.h:423
unsigned int height() const
Returns the height (the number of vertical including pixels) of this bounding box.
Definition: PixelBoundingBox.h:489
The following comfort class provides comfortable functions simplifying prototyping applications but a...
Definition: FrameFilterBlur.h:43
static bool blurMaskRegions(Frame &image, const Frame &mask, const unsigned int blurBorder=5u, RandomGenerator *randomGenerator=nullptr)
Blurs several masked regions in an image.
This class implements functions allowing to blur image content.
Definition: FrameFilterBlur.h:34
static bool blurMaskRegions8BitPerChannel(uint8_t *image, const uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int imagePaddingElements, const unsigned int maskPaddingElements, const unsigned int blurBorder=5u, RandomGenerator *randomGenerator=nullptr)
Blurs several masked regions in an image.
Definition: FrameFilterBlur.h:81
This class implements a simple information for a block/area of mask pixels.
Definition: segmentation/MaskAnalyzer.h:46
static void analyzeMaskSeparation8Bit(const uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, uint32_t *separation, const unsigned int separationPaddingElements, MaskBlocks &blocks)
Analyzes an 8 bit binary mask frame and separates the pixels into individual blocks of joined sub-mas...
std::vector< MaskBlock > MaskBlocks
Definition of a vector holding mask block objects.
Definition: segmentation/MaskAnalyzer.h:112
This class implements Ocean's image class.
Definition: Frame.h:1792
T * row(const unsigned int y, const unsigned int planeIndex=0u)
Returns the pointer to the pixel data of a specific row.
Definition: Frame.h:4177
Frame subFrame(const unsigned int subFrameLeft, const unsigned int subFrameTop, const unsigned int subFrameWidth, const unsigned int subFrameHeight, const CopyMode copyMode=CM_USE_KEEP_LAYOUT) const
Returns a sub-frame of this frame.
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
T * data(const unsigned int planeIndex=0u)
Returns a pointer to the pixel data of a specific plane.
Definition: Frame.h:4159
@ CM_USE_KEEP_LAYOUT
The source memory is used only, no copy is created, the padding layout is preserved.
Definition: Frame.h:1801
@ CM_COPY_REMOVE_PADDING_LAYOUT
Makes a copy of the source memory, but the new plane will not contain padding elements.
Definition: Frame.h:1803
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:4193
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
@ FORMAT_Y32
Pixel format with 32 bits Y frame.
Definition: Frame.h:639
@ FORMAT_Y8
Pixel format for grayscale images with byte order Y and 8 bits per pixel.
Definition: Frame.h:594
unsigned int width() const
Returns the width of the frame format in pixel.
Definition: Frame.h:3143
@ ORIGIN_UPPER_LEFT
The first pixel lies in the upper left corner, the last pixel in the lower right corner.
Definition: Frame.h:1050
unsigned int height() const
Returns the height of the frame in pixel.
Definition: Frame.h:3148
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 minmax(const T &lowerBoundary, const T &value, const T &upperBoundary)
This function fits a given parameter into a specified value range.
Definition: base/Utilities.h:903
std::vector< PixelPosition > PixelPositions
Definition of a vector holding pixel positions (with positive coordinate values).
Definition: PixelPosition.h:48
PixelPositionT< unsigned int > PixelPosition
Definition of the default PixelPosition object with a data type allowing only positive coordinate val...
Definition: PixelPosition.h:27
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