-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ssd
55 lines (45 loc) · 1.79 KB
/
ssd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
Copyright (C) 2018-2024 Geoffrey Daniels. https://gpdaniels.com/
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#ifndef GTL_VISION_MATCH_SCORE_SSD_HPP
#define GTL_VISION_MATCH_SCORE_SSD_HPP
// Summary: Sum of squared distances between two patches. [wip]
namespace gtl {
template<
int patch_width = 8,
int patch_height = 8,
typename type_lhs = unsigned char,
typename type_rhs = unsigned char
>
float ssd(
const type_lhs* __restrict data_lhs,
const int stride_lhs,
const type_rhs* __restrict data_rhs,
const int stride_rhs
) {
const int step_lhs = stride_lhs - patch_width;
const int step_rhs = stride_rhs - patch_width;
float sum = 0;
for (int y = 0; y < patch_height; ++y, data_lhs += step_lhs, data_rhs += step_rhs) {
for (int x = 0; x < patch_width; ++x, ++data_lhs, ++data_rhs) {
const float pixel_lhs = *data_lhs;
const float pixel_rhs = *data_rhs;
const float difference = pixel_lhs - pixel_rhs;
const float difference_squared = difference * difference;
sum += difference_squared;
}
}
return sum;
}
}
#endif // GTL_VISION_MATCH_SCORE_SSD_HPP