ClusterCorrespondence.hpp 1.15 KB
/* 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