ClusterCorrespondence.hpp
1.15 KB
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
/* Analysis of the outer divertor hot spot activity in the protection video
camera recordings at JET */
#pragma once
#include <opencv2/imgproc.hpp>
namespace Cpu {
class ClusterCorrespondence {
public:
ClusterCorrespondence(float minOverlap, float maxOversize)
: minOverlap(minOverlap), maxOversize(maxOversize) {}
bool corresponds(const cv::Mat &first, const cv::Mat &second) {
cv::bitwise_and(first, second, overlap);
const auto firstArea = cv::countNonZero(first),
secondArea = cv::countNonZero(second),
overlapArea = cv::countNonZero(overlap);
return isOverlapping(firstArea, secondArea, overlapArea) &&
isSimilar(firstArea, secondArea);
}
private:
float minOverlap;
float maxOversize;
bool isOverlapping(int firstArea, int secondArea, int overlapArea) const {
return overlapArea >= minOverlap * std::min(firstArea, secondArea);
}
bool isSimilar(int firstArea, int secondArea) const {
return (firstArea / static_cast<float>(secondArea) >=
1.F / maxOversize) &&
(firstArea / static_cast<float>(secondArea) <= maxOversize);
}
/* Buffors */
cv::Mat overlap;
};
} // namespace Cpu