I’m processing an images containing both full circles and circle segments. The image consists of both full circles and circle segments. My goal is to merge only those components that are part of the same circle but are not complete circles themselves.
Currently, I’m using the following method to extract connected points from the input image:
std::vector<std::vector<cv::Point>> GetConnectedPoints(cv::Mat& binaryImage) {
cv::Mat labels, stats, centroids;
int numComponents = cv::connectedComponentsWithStats(binaryImage, labels, stats, centroids);
std::vector<std::vector<cv::Point>> components(numComponents);
for (int label = 1; label < stats.rows; ++label) {
int left = stats.at<int>(label, cv::CC_STAT_LEFT);
int top = stats.at<int>(label, cv::CC_STAT_TOP);
int width = stats.at<int>(label, cv::CC_STAT_WIDTH);
int height = stats.at<int>(label, cv::CC_STAT_HEIGHT);
for (int y = top; y < top + height; ++y) {
for (int x = left; x < left + width; ++x) {
if (labels.at<int>(y, x) == label) {
components[label].emplace_back(x, y);
}
}
}
}
return components;
}
The components are concentric circle shapes, which include full circles and circle segments. Here is an example image showing the connected points, where different colors indicate different components:
How can I merge only those components that are segments of the same circle? Any guidance or code on how to approach this problem would be greatly appreciated.
Thank you!