8 #ifndef META_OCEAN_CV_SUM_ABSOLUTE_DIFFERENCES_H
9 #define META_OCEAN_CV_SUM_ABSOLUTE_DIFFERENCES_H
50 template <
unsigned int tChannels,
unsigned int tPatchSize>
51 static inline uint32_t
patch8BitPerChannel(
const uint8_t*
const image0,
const uint8_t*
const image1,
const unsigned int width0,
const unsigned int width1,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int centerX1,
const unsigned int centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements);
65 template <
unsigned int tChannels,
unsigned int tPatchSize>
66 static inline uint32_t
patchBuffer8BitPerChannel(
const uint8_t*
const image0,
const unsigned int width0,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int image0PaddingElements,
const uint8_t*
const buffer1);
76 template <
unsigned int tChannels,
unsigned int tPixels>
97 template <
unsigned int tChannels,
unsigned int tPatchSize>
98 static uint32_t
patchMirroredBorder8BitPerChannel(
const uint8_t* image0,
const uint8_t* image1,
const unsigned int width0,
const unsigned int height0,
const unsigned int width1,
const unsigned int height1,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int centerX1,
const unsigned int centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements);
112 template <
typename T,
unsigned int tChannels>
113 static void determine(
const T* firstFrame,
const T* secondFrame,
const unsigned int width,
const unsigned int height,
typename AbsoluteDifferenceValueTyper<T>::Type* absoluteDifferences,
const unsigned int firstFramePaddingElements,
const unsigned int secondFramePaddingElements);
125 template <
unsigned int tChannels,
unsigned int tPatchSize>
126 inline uint32_t
SumAbsoluteDifferences::patch8BitPerChannel(
const uint8_t* image0,
const uint8_t* image1,
const unsigned int width0,
const unsigned int width1,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int centerX1,
const unsigned int centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements)
128 static_assert(tChannels >= 1u,
"Invalid channel number!");
129 static_assert(tPatchSize % 2u == 1u,
"Invalid patch size!");
131 ocean_assert(image0 !=
nullptr && image1 !=
nullptr);
133 ocean_assert(width0 >= tPatchSize);
134 ocean_assert(width1 >= tPatchSize);
136 constexpr
unsigned int tPatchSize_2 = tPatchSize / 2u;
138 ocean_assert(centerX0 >= tPatchSize_2 && centerY0 >= tPatchSize_2);
139 ocean_assert(centerX1 >= tPatchSize_2 && centerY1 >= tPatchSize_2);
141 ocean_assert(centerX0 < width0 - tPatchSize_2);
142 ocean_assert(centerX1 < width1 - tPatchSize_2);
144 const unsigned int image0StrideElements = width0 * tChannels + image0PaddingElements;
145 const unsigned int image1StrideElements = width1 * tChannels + image1PaddingElements;
147 const uint8_t*
const patch0 = image0 + (centerY0 - tPatchSize_2) * image0StrideElements + (centerX0 - tPatchSize_2) * tChannels;
148 const uint8_t*
const patch1 = image1 + (centerY1 - tPatchSize_2) * image1StrideElements + (centerX1 - tPatchSize_2) * tChannels;
150 #if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION >= 41
152 if constexpr (tPatchSize >= 5u)
154 return SumAbsoluteDifferencesSSE::patch8BitPerChannel<tChannels, tPatchSize>(patch0, patch1, image0StrideElements, image1StrideElements);
157 #elif defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION >= 10
159 if constexpr (tPatchSize >= 5u)
161 return SumAbsoluteDifferencesNEON::patch8BitPerChannel<tChannels, tPatchSize>(patch0, patch1, image0StrideElements, image1StrideElements);
166 return SumAbsoluteDifferencesBase::patch8BitPerChannelTemplate<tChannels, tPatchSize>(patch0, patch1, image0StrideElements, image1StrideElements);
169 template <
unsigned int tChannels,
unsigned int tPatchSize>
172 static_assert(tChannels >= 1u,
"Invalid channel number!");
173 static_assert(tPatchSize % 2u == 1u,
"Invalid patch size!");
175 ocean_assert(image0 !=
nullptr && buffer1 !=
nullptr);
177 ocean_assert(width0 >= tPatchSize);
179 constexpr
unsigned int tPatchSize_2 = tPatchSize / 2u;
181 ocean_assert(centerX0 >= tPatchSize_2 && centerY0 >= tPatchSize_2);
183 ocean_assert(centerX0 < width0 - tPatchSize_2);
185 const unsigned int image0StrideElements = width0 * tChannels + image0PaddingElements;
187 const uint8_t*
const patch0 = image0 + (centerY0 - tPatchSize_2) * image0StrideElements + (centerX0 - tPatchSize_2) * tChannels;
189 #if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION >= 41
191 if constexpr (tPatchSize >= 5u)
193 return SumAbsoluteDifferencesSSE::patchBuffer8BitPerChannel<tChannels, tPatchSize>(patch0, buffer1, image0StrideElements);
196 #elif defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION >= 10
198 if constexpr (tPatchSize >= 5u)
200 return SumAbsoluteDifferencesNEON::patchBuffer8BitPerChannel<tChannels, tPatchSize>(patch0, buffer1, image0StrideElements);
205 return SumAbsoluteDifferencesBase::patchBuffer8BitPerChannelTemplate<tChannels, tPatchSize>(patch0, buffer1, image0StrideElements);
208 template <
unsigned int tChannels,
unsigned int tPixels>
211 static_assert(tChannels >= 1u,
"Invalid channel number!");
212 static_assert(tPixels >= 1u,
"Invalid pixel number!");
214 constexpr
unsigned int tElements = tChannels * tPixels;
216 #if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION >= 41
218 if constexpr (tElements >= 15u)
220 return SumAbsoluteDifferencesSSE::buffer8BitPerChannel<tElements>(buffer0, buffer1);
223 #elif defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION >= 10
225 if constexpr (tElements >= 8u)
227 return SumAbsoluteDifferencesNEON::buffer8BitPerChannel<tElements>(buffer0, buffer1);
232 return SumAbsoluteDifferencesBase::buffer8BitPerChannelTemplate<tElements>(buffer0, buffer1);
235 template <
unsigned int tChannels,
unsigned int tPatchSize>
236 uint32_t
SumAbsoluteDifferences::patchMirroredBorder8BitPerChannel(
const uint8_t* image0,
const uint8_t* image1,
const unsigned int width0,
const unsigned int height0,
const unsigned int width1,
const unsigned int height1,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int centerX1,
const unsigned int centerY1,
const unsigned int image0PaddingElements,
const unsigned int image1PaddingElements)
238 static_assert(tChannels >= 1u,
"Invalid channel number!");
239 static_assert(tPatchSize % 2u == 1u,
"Invalid patch size!");
241 return SumAbsoluteDifferencesBase::patchMirroredBorder8BitPerChannelTemplate<tChannels>(image0, image1, tPatchSize, width0, height0, width1, height1, centerX0, centerY0, centerX1, centerY1, image0PaddingElements, image1PaddingElements);
244 template <
typename T,
unsigned int tChannels>
247 ocean_assert(firstFrame !=
nullptr);
248 ocean_assert(secondFrame !=
nullptr);
249 ocean_assert(width != 0u && height != 0u);
250 ocean_assert(absoluteDifferences !=
nullptr);
255 const unsigned int firstFrameStrideElements = width * tChannels + firstFramePaddingElements;
256 const unsigned int secondFrameStrideElements = width * tChannels + secondFramePaddingElements;
258 TResult result[tChannels];
260 for (
unsigned int n = 0u; n < tChannels; ++n)
262 result[n] = TResult(0);
265 for (
unsigned int y = 0u; y < height; ++y)
267 for (
unsigned int x = 0u; x < width; ++x)
269 for (
unsigned int n = 0u; n < tChannels; ++n)
275 firstFrame += firstFrameStrideElements;
276 secondFrame += secondFrameStrideElements;
279 for (
unsigned int n = 0u; n < tChannels; ++n)
281 absoluteDifferences[n] = result[n];
291 absoluteDifferences.clear();
298 for (
unsigned int planeIndex = 0u; planeIndex < firstFrame.
numberPlanes(); ++planeIndex)
304 unsigned int planeAbsoluteDifference = 0u;
306 absoluteDifferences.emplace_back(planeAbsoluteDifference);
312 unsigned int planeAbsoluteDifferences[2] = {0u, 0u};
314 absoluteDifferences.emplace_back(planeAbsoluteDifferences[0]);
315 absoluteDifferences.emplace_back(planeAbsoluteDifferences[1]);
321 unsigned int planeAbsoluteDifferences[3] = {0u, 0u, 0u};
323 absoluteDifferences.emplace_back(planeAbsoluteDifferences[0]);
324 absoluteDifferences.emplace_back(planeAbsoluteDifferences[1]);
325 absoluteDifferences.emplace_back(planeAbsoluteDifferences[2]);
331 unsigned int planeAbsoluteDifferences[4] = {0u, 0u, 0u, 0u};
333 absoluteDifferences.emplace_back(planeAbsoluteDifferences[0]);
334 absoluteDifferences.emplace_back(planeAbsoluteDifferences[1]);
335 absoluteDifferences.emplace_back(planeAbsoluteDifferences[2]);
336 absoluteDifferences.emplace_back(planeAbsoluteDifferences[3]);
341 ocean_assert(
false &&
"Invalid channel number!");
unsigned long long Type
Definition of the data type for the absolute difference value.
Definition: DataType.h:225
This class implements several sum of absolute differences functions.
Definition: SumAbsoluteDifferencesBase.h:25
This class implements functions calculation the sum of absolute differences.
Definition: SumAbsoluteDifferences.h:31
static uint32_t patchMirroredBorder8BitPerChannel(const uint8_t *image0, const uint8_t *image1, const unsigned int width0, const unsigned int height0, const unsigned int width1, const unsigned int height1, const unsigned int centerX0, const unsigned int centerY0, const unsigned int centerX1, const unsigned int centerY1, const unsigned int image0PaddingElements, const unsigned int image1PaddingElements)
Returns the sum of absolute differences between two patches within an image, patch pixels outside the...
Definition: SumAbsoluteDifferences.h:236
static uint32_t buffer8BitPerChannel(const uint8_t *buffer0, const uint8_t *buffer1)
Returns the sum of square differences between two memory buffers.
Definition: SumAbsoluteDifferences.h:209
static void determine(const T *firstFrame, const T *secondFrame, const unsigned int width, const unsigned int height, typename AbsoluteDifferenceValueTyper< T >::Type *absoluteDifferences, const unsigned int firstFramePaddingElements, const unsigned int secondFramePaddingElements)
Determines the sum of absolute differences between two individual frames, individually for each chann...
Definition: SumAbsoluteDifferences.h:245
static uint32_t patch8BitPerChannel(const uint8_t *const image0, const uint8_t *const image1, const unsigned int width0, const unsigned int width1, const unsigned int centerX0, const unsigned int centerY0, const unsigned int centerX1, const unsigned int centerY1, const unsigned int image0PaddingElements, const unsigned int image1PaddingElements)
Returns the sum of absolute differences between two square image patches.
Definition: SumAbsoluteDifferences.h:126
static uint32_t patchBuffer8BitPerChannel(const uint8_t *const image0, const unsigned int width0, const unsigned int centerX0, const unsigned int centerY0, const unsigned int image0PaddingElements, const uint8_t *const buffer1)
Returns the sum of absolute differences between an image patch and a memory buffer.
Definition: SumAbsoluteDifferences.h:170
T Type
Definition of the data type for the signed difference value.
Definition: DataType.h:176
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
const FrameType & frameType() const
Returns the frame type of this frame.
Definition: Frame.h:3775
bool isValid() const
Returns whether this frame is valid.
Definition: Frame.h:4448
unsigned int planeChannels(const unsigned int planeIndex) const
Returns the channels of a plane of this frame.
Definition: Frame.h:4090
unsigned int planeWidth(const unsigned int planeIndex) const
Returns the width of a plane of this frame.
Definition: Frame.h:4074
unsigned int planeHeight(const unsigned int planeIndex) const
Returns the height of a plane of this frame.
Definition: Frame.h:4082
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
uint32_t numberPlanes() const
Returns the number of planes of the pixel format of this frame.
Definition: Frame.h:3183
@ DT_UNSIGNED_INTEGER_8
Unsigned 8 bit integer data type (uint8_t).
Definition: Frame.h:41
DataType dataType() const
Returns the data type of the pixel format of this frame.
Definition: Frame.h:3163
This class provides basic numeric functionalities.
Definition: Numeric.h:57
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15