8 #ifndef META_OCEAN_CV_SUM_SQUARE_DIFFERENCES_H
9 #define META_OCEAN_CV_SUM_SQUARE_DIFFERENCES_H
48 template <
unsigned int tChannels,
unsigned int tPatchSize>
49 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);
63 template <
unsigned int tChannels,
unsigned int tPatchSize>
64 static inline unsigned int 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);
74 template <
unsigned int tChannels,
unsigned int tPixels>
75 static inline uint32_t
buffer8BitPerChannel(
const uint8_t*
const buffer0,
const uint8_t*
const buffer1);
95 template <
unsigned int tChannels,
unsigned int tPatchSize>
96 static inline IndexPair32 patchAtBorder8BitPerChannel(
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);
116 template <
unsigned int tChannels,
unsigned int tPatchSize>
117 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);
120 template <
unsigned int tChannels,
unsigned int tPatchSize>
121 inline uint32_t
SumSquareDifferences::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)
123 static_assert(tChannels >= 1u,
"Invalid channel number!");
124 static_assert(tPatchSize >= 1u,
"Invalid patch size!");
126 ocean_assert(image0 !=
nullptr && image1 !=
nullptr);
128 ocean_assert(width0 >= tPatchSize);
129 ocean_assert(width1 >= tPatchSize);
131 constexpr
unsigned int tPatchSize_2 = tPatchSize / 2u;
133 ocean_assert(centerX0 >= tPatchSize_2 && centerY0 >= tPatchSize_2);
134 ocean_assert(centerX1 >= tPatchSize_2 && centerY1 >= tPatchSize_2);
136 ocean_assert(centerX0 < width0 - tPatchSize_2);
137 ocean_assert(centerX1 < width1 - tPatchSize_2);
139 const unsigned int image0StrideElements = width0 * tChannels + image0PaddingElements;
140 const unsigned int image1StrideElements = width1 * tChannels + image1PaddingElements;
142 const uint8_t*
const patch0 = image0 + (centerY0 - tPatchSize_2) * image0StrideElements + (centerX0 - tPatchSize_2) * tChannels;
143 const uint8_t*
const patch1 = image1 + (centerY1 - tPatchSize_2) * image1StrideElements + (centerX1 - tPatchSize_2) * tChannels;
145 #if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION >= 41
147 if constexpr (tPatchSize >= 5u)
149 return SumSquareDifferencesSSE::patch8BitPerChannel<tChannels, tPatchSize>(patch0, patch1, image0StrideElements, image1StrideElements);
152 #elif defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION >= 10
154 if constexpr (tPatchSize >= 5u)
156 return SumSquareDifferencesNEON::patch8BitPerChannel<tChannels, tPatchSize>(patch0, patch1, image0StrideElements, image1StrideElements);
161 return SumSquareDifferencesBase::patch8BitPerChannelTemplate<tChannels, tPatchSize>(patch0, patch1, image0StrideElements, image1StrideElements);
164 template <
unsigned int tChannels,
unsigned int tPatchSize>
165 inline uint32_t
SumSquareDifferences::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)
167 static_assert(tChannels >= 1u,
"Invalid channel number!");
168 static_assert(tPatchSize % 2u == 1u,
"Invalid patch size!");
170 ocean_assert(image0 !=
nullptr && buffer1 !=
nullptr);
172 ocean_assert(width0 >= tPatchSize);
174 constexpr
unsigned int tPatchSize_2 = tPatchSize / 2u;
176 ocean_assert(centerX0 >= tPatchSize_2 && centerY0 >= tPatchSize_2);
178 ocean_assert(centerX0 < width0 - tPatchSize_2);
180 const unsigned int image0StrideElements = width0 * tChannels + image0PaddingElements;
182 const uint8_t*
const patch0 = image0 + (centerY0 - tPatchSize_2) * image0StrideElements + (centerX0 - tPatchSize_2) * tChannels;
184 #if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION >= 41
186 if constexpr (tPatchSize >= 5u)
188 return SumSquareDifferencesSSE::patchBuffer8BitPerChannel<tChannels, tPatchSize>(patch0, buffer1, image0StrideElements);
191 #elif defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION >= 10
193 if constexpr (tPatchSize >= 5u)
195 return SumSquareDifferencesNEON::patchBuffer8BitPerChannel<tChannels, tPatchSize>(patch0, buffer1, image0StrideElements);
200 return SumSquareDifferencesBase::patchBuffer8BitPerChannelTemplate<tChannels, tPatchSize>(patch0, buffer1, image0StrideElements);
203 template <
unsigned int tChannels,
unsigned int tPixels>
206 static_assert(tChannels >= 1u,
"Invalid channel number!");
207 static_assert(tPixels >= 1u,
"Invalid pixel number!");
209 constexpr
unsigned int tElements = tChannels * tPixels;
211 #if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION >= 41
213 if constexpr (tElements >= 15u)
215 return SumSquareDifferencesSSE::buffer8BitPerChannel<tElements>(buffer0, buffer1);
218 #elif defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION >= 10
220 if constexpr (tElements >= 8u)
222 return SumSquareDifferencesNEON::buffer8BitPerChannel<tElements>(buffer0, buffer1);
227 return SumSquareDifferencesBase::buffer8BitPerChannelTemplate<tElements>(buffer0, buffer1);
230 template <
unsigned int tChannels,
unsigned int tPatchSize>
231 inline IndexPair32 SumSquareDifferences::patchAtBorder8BitPerChannel(
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)
233 static_assert(tChannels >= 1u,
"Invalid channel number!");
234 static_assert(tPatchSize % 2u == 1u,
"Invalid patch size!");
236 return SumSquareDifferencesBase::patchAtBorder8BitPerChannelTemplate<tChannels, tPatchSize>(image0, image1, width0, height0, width1, height1, centerX0, centerY0, centerX1, centerY1, image0PaddingElements, image1PaddingElements);
239 template <
unsigned int tChannels,
unsigned int tPatchSize>
240 uint32_t
SumSquareDifferences::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)
242 static_assert(tChannels >= 1u,
"Invalid channel number!");
243 static_assert(tPatchSize % 2u == 1u,
"Invalid patch size!");
245 #if defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION >= 10
247 if constexpr (tPatchSize >= 5u)
249 return SumSquareDifferencesNEON::patchMirroredBorder8BitPerChannel<tChannels, tPatchSize>(image0, image1, width0, height0, width1, height1, centerX0, centerY0, centerX1, centerY1, image0PaddingElements, image1PaddingElements);
254 return SumSquareDifferencesBase::patchMirroredBorder8BitPerChannelTemplate<tChannels>(image0, image1, tPatchSize, width0, height0, width1, height1, centerX0, centerY0, centerX1, centerY1, image0PaddingElements, image1PaddingElements);
This class implements several sum square differences functions based e.g., on template parameters.
Definition: SumSquareDifferencesBase.h:25
This class implements functions calculating the sum of square differences.
Definition: SumSquareDifferences.h:29
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 square differences between two square image patches.
Definition: SumSquareDifferences.h:121
static uint32_t buffer8BitPerChannel(const uint8_t *const buffer0, const uint8_t *const buffer1)
Returns the sum of square differences between two memory buffers.
Definition: SumSquareDifferences.h:204
static unsigned int 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 square differences between an image patch and a memory buffer.
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 square differences between two patches within an image, patch pixels outside the i...
Definition: SumSquareDifferences.h:240
static IndexPair32 patchAtBorder8BitPerChannel(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 square differences between two square image patches which can be partially outside...
Definition: SumSquareDifferences.h:231
std::pair< Index32, Index32 > IndexPair32
Definition of a pair holding 32 bit indices.
Definition: Base.h:138
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15