8 #ifndef META_OCEAN_CV_FRAME_MEAN_FILTER_H
9 #define META_OCEAN_CV_FRAME_MEAN_FILTER_H
77 template <
unsigned int tChannels>
78 static void filter8BitPerChannel(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const unsigned int window,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
90 template <
unsigned int tChannels>
91 static void filter8BitPerChannel(uint8_t* frame,
const unsigned int width,
const unsigned int height,
const unsigned int window,
const unsigned int framePaddingElements,
Worker* worker =
nullptr);
106 template <
unsigned int tChannels>
107 static void filterWithIntegral8BitPerChannel(
const uint32_t* borderedIntegral, uint8_t* target,
const unsigned int width,
const unsigned int height,
const unsigned int window,
const unsigned int borderedIntegralPaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
125 template <
unsigned int tChannels>
126 static void filterWithIntegral8BitPerChannelSubset(
const uint32_t* borderedIntegral, uint8_t* target,
const unsigned int width,
const unsigned int height,
const unsigned int window,
const unsigned int borderedIntegralPaddingElements,
const unsigned int targetPaddingElements,
const unsigned int firstRow,
const unsigned int numberRows);
129 template <
unsigned int tChannels>
130 void FrameFilterMean::filter8BitPerChannel(
const uint8_t* source, uint8_t* target,
const unsigned int width,
const unsigned int height,
const unsigned int window,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker)
132 static_assert(tChannels >= 1u,
"Invalid channel number!");
134 ocean_assert(source !=
nullptr && target !=
nullptr);
135 ocean_assert(window % 2u == 1u);
137 const unsigned int border = window / 2u;
139 const unsigned int integralWidth = width + window;
140 const unsigned int integralHeight = height + window;
143 CV::IntegralImage::createBorderedImageMirror<uint8_t, uint32_t, tChannels>(source, integralFrame.
data<uint32_t>(), width, height, border, sourcePaddingElements, integralFrame.
paddingElements());
145 filterWithIntegral8BitPerChannel<tChannels>(integralFrame.
constdata<uint32_t>(), target, width, height, window, integralFrame.
paddingElements(), targetPaddingElements, worker);
148 template <
unsigned int tChannels>
151 static_assert(tChannels >= 1u,
"Invalid channel number!");
153 ocean_assert(frame !=
nullptr);
154 ocean_assert(window % 2u == 1u);
156 const unsigned int border = window / 2u;
158 const unsigned int integralWidth = width + window;
159 const unsigned int integralHeight = height + window;
162 CV::IntegralImage::createBorderedImageMirror<uint8_t, uint32_t, tChannels>(frame, integralFrame.
data<uint32_t>(), width, height, border, framePaddingElements, integralFrame.
paddingElements());
164 filterWithIntegral8BitPerChannel<tChannels>(integralFrame.
constdata<uint32_t>(), frame, width, height, window, integralFrame.
paddingElements(), framePaddingElements, worker);
167 template <
unsigned int tChannels>
168 inline void FrameFilterMean::filterWithIntegral8BitPerChannel(
const uint32_t* borderedIntegral, uint8_t* target,
const unsigned int width,
const unsigned int height,
const unsigned int window,
const unsigned int borderedIntegralPaddingElements,
const unsigned int targetPaddingElements,
Worker* worker)
170 static_assert(tChannels >= 1u,
"Invalid channel number!");
172 ocean_assert(borderedIntegral !=
nullptr && target !=
nullptr);
173 ocean_assert(window % 2u == 1u);
177 worker->
executeFunction(
Worker::Function::createStatic(&FrameFilterMean::filterWithIntegral8BitPerChannelSubset<tChannels>, borderedIntegral, target, width, height, window, borderedIntegralPaddingElements, targetPaddingElements, 0u, 0u), 0u, height);
181 filterWithIntegral8BitPerChannelSubset<tChannels>(borderedIntegral, target, width, height, window, borderedIntegralPaddingElements, targetPaddingElements, 0u, height);
185 template <
unsigned int tChannels>
186 void FrameFilterMean::filterWithIntegral8BitPerChannelSubset(
const uint32_t* borderedIntegral, uint8_t* target,
const unsigned int width,
const unsigned int height,
const unsigned int window,
const unsigned int borderedIntegralPaddingElements,
const unsigned int targetPaddingElements,
const unsigned int firstRow,
const unsigned int numberRows)
188 ocean_assert(borderedIntegral !=
nullptr && target !=
nullptr);
189 ocean_assert(window % 2u == 1u);
191 ocean_assert_and_suppress_unused(firstRow + numberRows <= height, height);
193 const unsigned int borderedIntegralStrideElements = (width + window) * tChannels + borderedIntegralPaddingElements;
194 const unsigned int targetStrideElements = width * tChannels + targetPaddingElements;
196 const unsigned int integralSkipElements = window * tChannels + borderedIntegralPaddingElements;
198 const unsigned int area = window * window;
199 const unsigned int area_2 = (area + 1u) / 2u;
201 const uint32_t* integralTopLeft = borderedIntegral + firstRow * borderedIntegralStrideElements;
202 const uint32_t* integralBottomLeft = borderedIntegral + (firstRow + window) * borderedIntegralStrideElements;
204 const uint32_t* integralTopRight = integralTopLeft + window * tChannels;
205 const uint32_t* integralBottomRight = integralBottomLeft + window * tChannels;
207 uint8_t* targetRow = target + firstRow * targetStrideElements;
209 for (
unsigned int y = 0u; y < numberRows; ++y)
211 ocean_assert((integralTopLeft - borderedIntegral) % borderedIntegralStrideElements == 0u);
212 ocean_assert((integralBottomLeft - borderedIntegral) % borderedIntegralStrideElements == 0u);
214 for (
unsigned int x = 0u; x < width; ++x)
216 for (
unsigned int n = 0u; n < tChannels; ++n)
218 ocean_assert((*integralTopLeft - *integralTopRight - *integralBottomLeft + *integralBottomRight + area_2) / area <= 255u);
220 *targetRow++ = uint8_t((*integralTopLeft++ - *integralTopRight++ - *integralBottomLeft++ + *integralBottomRight++ + area_2) / area);
224 integralTopLeft += integralSkipElements;
225 integralBottomLeft += integralSkipElements;
227 integralTopRight += integralSkipElements;
228 integralBottomRight += integralSkipElements;
230 targetRow += targetPaddingElements;
This class implements a mean frame filter.
Definition: FrameFilterMean.h:28
FilterMask
Definition of different mean filter masks.
Definition: FrameFilterMean.h:35
static void filter8BitPerChannel(const uint8_t *source, uint8_t *target, const unsigned int width, const unsigned int height, const unsigned int window, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Filters a given frame using a mean filter with arbitrary windows size by internally using a bordered ...
Definition: FrameFilterMean.h:130
static bool filter(const Frame &source, Frame &target, const unsigned int window, Worker *worker=nullptr)
Filters a given frame using a mean filter with arbitrary size by internally using a bordered integral...
static void filterWithIntegral8BitPerChannel(const uint32_t *borderedIntegral, uint8_t *target, const unsigned int width, const unsigned int height, const unsigned int window, const unsigned int borderedIntegralPaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Filters a frame using a mean filter with arbitrary size by using a bordered integral image.
Definition: FrameFilterMean.h:168
static void filterWithIntegral8BitPerChannelSubset(const uint32_t *borderedIntegral, uint8_t *target, const unsigned int width, const unsigned int height, const unsigned int window, const unsigned int borderedIntegralPaddingElements, const unsigned int targetPaddingElements, const unsigned int firstRow, const unsigned int numberRows)
Filters a subset of a frame using a mean filter with arbitrary size by using a bordered integral imag...
Definition: FrameFilterMean.h:186
static bool filter(Frame &frame, const unsigned int window, Worker *worker=nullptr)
Filters a given frame using a mean filter with arbitrary size by internally using a bordered integral...
static Caller< void > createStatic(typename StaticFunctionPointerMaker< void, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass >::Type function)
Creates a new caller container for a static function with no function parameter.
Definition: Caller.h:2876
This class implements Ocean's image class.
Definition: Frame.h:1792
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
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
@ ORIGIN_UPPER_LEFT
The first pixel lies in the upper left corner, the last pixel in the lower right corner.
Definition: Frame.h:1050
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
bool executeFunction(const Function &function, const unsigned int first, const unsigned int size, const unsigned int firstIndex=(unsigned int)(-1), const unsigned int sizeIndex=(unsigned int)(-1), const unsigned int minimalIterations=1u, const unsigned int threadIndex=(unsigned int)(-1))
Executes a callback function separable by two function parameters.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15