Ocean
SumSquareDifferencesNoCenter.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_CV_ADVANCED_SUM_SQUARE_DIFFERENCES_NO_CENTER_H
9 #define META_OCEAN_CV_ADVANCED_SUM_SQUARE_DIFFERENCES_NO_CENTER_H
10 
15 
16 namespace Ocean
17 {
18 
19 namespace CV
20 {
21 
22 namespace Advanced
23 {
24 
25 /**
26  * This class implements functions calculating the sum of square differences and omit center pixel.
27  * @ingroup cvadvanced
28  */
30 {
31  public:
32 
33  /**
34  * Returns the sum of square differences between two square patches while skipping the center pixel.
35  * @param image0 The image in which the first patch is located, must be valid
36  * @param image1 The image in which the second patch is located, must be valid
37  * @param width0 The width of the first image, in pixels, with range [tPatchSize, infinity)
38  * @param width1 The width of the second image, in pixels, with range [tPatchSize, infinity)
39  * @param centerX0 Horizontal center position of the (tPatchSize x tPatchSize) block in the first frame, with range [tPatchSize/2, width - tPatchSize/2 - 1]
40  * @param centerY0 Vertical center position of the (tPatchSize x tPatchSize) block in the first frame, with range [tPatchSize/2, height - tPatchSize/2 - 1]
41  * @param centerX1 Horizontal center position of the (tPatchSize x tPatchSize) block in the second frame, with range [tPatchSize/2, width - tPatchSize/2 - 1]
42  * @param centerY1 Vertical center position of the (tPatchSize x tPatchSize) block in the second frame, with range [tPatchSize/2, height - tPatchSize/2 - 1]
43  * @param image0PaddingElements The number of padding elements at the end of each row of the first image, in elements, with range [0, infinity)
44  * @param image1PaddingElements The number of padding elements at the end of each row of the second image, in elements, with range [0, infinity)
45  * @return The resulting sum of square differences, with range [0, infinity)
46  * @tparam tChannels The number of frame channels, with range [1, infinity)
47  * @tparam tPatchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
48  */
49  template <unsigned int tChannels, unsigned int tPatchSize>
50  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);
51 };
52 
53 template <unsigned int tChannels, unsigned int tPatchSize>
54 inline uint32_t SumSquareDifferencesNoCenter::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)
55 {
56  static_assert(tChannels >= 1u, "Invalid channel number!");
57  static_assert(tPatchSize >= 1u, "Invalid patch size!");
58 
59  ocean_assert(image0 != nullptr && image1 != nullptr);
60 
61  ocean_assert(width0 >= tPatchSize);
62  ocean_assert(width1 >= tPatchSize);
63 
64  constexpr unsigned int tPatchSize_2 = tPatchSize / 2u;
65 
66  ocean_assert(centerX0 >= tPatchSize_2 && centerY0 >= tPatchSize_2);
67  ocean_assert(centerX1 >= tPatchSize_2 && centerY1 >= tPatchSize_2);
68 
69  ocean_assert(centerX0 < width0 - tPatchSize_2);
70  ocean_assert_and_suppress_unused(centerX1 < width1 - tPatchSize_2, tPatchSize_2);
71 
72 #if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION >= 41
73 
74  if constexpr (tPatchSize >= 5u)
75  {
76  return SumSquareDifferencesNoCenterSSE::patch8BitPerChannel<tChannels, tPatchSize>(image0, image1, width0, width1, centerX0, centerY0, centerX1, centerY1, image0PaddingElements, image1PaddingElements);
77  }
78 
79 #elif defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION >= 10
80 
81  if constexpr (tPatchSize >= 5u)
82  {
83  return SumSquareDifferencesNoCenterNEON::patch8BitPerChannel<tChannels, tPatchSize>(image0, image1, width0, width1, centerX0, centerY0, centerX1, centerY1, image0PaddingElements, image1PaddingElements);
84  }
85 
86 #endif // OCEAN_HARDWARE_SSE_VERSION, OCEAN_HARDWARE_NEON_VERSION
87 
88  return SumSquareDifferencesNoCenterBase::patch8BitPerChannelTemplate<tChannels, tPatchSize>(image0, image1, width0, width1, centerX0, centerY0, centerX1, centerY1, image0PaddingElements, image1PaddingElements);
89 }
90 
91 }
92 
93 }
94 
95 }
96 
97 #endif // META_OCEAN_CV_ADVANCED_SUM_SQUARE_DIFFERENCES_NO_CENTER_H
This class implements functions calculating the sum of square differences and omits center pixel.
Definition: SumSquareDifferencesNoCenterBase.h:30
This class implements functions calculating the sum of square differences and omit center pixel.
Definition: SumSquareDifferencesNoCenter.h:30
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 patches while skipping the center pixel.
Definition: SumSquareDifferencesNoCenter.h:54
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15