본문 바로가기
  • AI 개발자가 될래요
컴퓨터비전

[C++/Opencv] Equilvalence table Labeling

by 꿀개 2022. 3. 7.

동차테이블을 이용한 라벨링 프로그래밍중이다.

공부하면서 중요한거 정리할 예정

 

관련 논문: SparseCCL: Connected Components Labeling and Analysis for sparse images

 

참고 페이지

- Connected-component labeling

https://en.wikipedia.org/wiki/Connected-component_labeling#Algorithms

 

Connected-component labeling - Wikipedia

Connected-component labeling (CCL), connected-component analysis (CCA), blob extraction, region labeling, blob discovery, or region extraction is an algorithmic application of graph theory, where subsets of connected components are uniquely labeled based o

en.wikipedia.org

 

https://birthxmas.tistory.com/230

 

[컴퓨터 비전] Connected Component Labeling

□ 문제 1. 첨부된 영상 T-3m1-inv.pgm을 입력으로 하여, 흰 dot영역이 1이되고, 검은 배경영역이 0이 되도록 이진화를 한 후, connected component labeling을 수행하여, 각 dot 영역의 면..

birthxmas.tistory.com

 

- Binary Image Analysis : 이진화 방법에 대해 자세히 나와있어서 학습에 도움이 된다.

http://www.cse.msu.edu/~stockman/Book/2002/Chapters/ch3.pdf

 

- Hoshen–Kopelman algorithm

https://en.wikipedia.org/wiki/Hoshen%E2%80%93Kopelman_algorithm

 

Hoshen–Kopelman algorithm - Wikipedia

From Wikipedia, the free encyclopedia Jump to navigation Jump to search Algorithm for labeling clusters on a grid The Hoshen–Kopelman algorithm is a simple and efficient algorithm for labeling clusters on a grid, where the grid is a regular network of ce

en.wikipedia.org

 

소스코드

- 2번 기반

if (i == 0 && j == 0) {
    if (image.at<uchar>(i, j) > 0) {
        label_count++;
        result.at<float>(i, j) = label_count;
        eq_table[label_count+1] = label_count;
    }
}
if (i == 0&&j!=0) {
    if (image.at<uchar>(i, j-1) > 0) {
    result.at<float>(i, j) = result.at<float>(i, j-1);
    }
else {
    label_count++;
    result.at<float>(i, j) = label_count;
    eq_table[label_count + 1] = label_count;
	}
}
if (i != 0 && j == 0) {
    if (image.at<uchar>(i-1, j) > 0) {
    result.at<float>(i, j) = result.at<float>(i-1, j);
    }
    else {
        label_count++;
        result.at<float>(i, j) = label_count;
        eq_table[label_count + 1] = label_count;
    }
}
if ((i != 0&& j != 0)&&image.at<uchar>(i-1, j) > 0 && image.at<uchar>(i, j-1) > 0) {  //왼, 위 다 값 있을 때
    if (result.at<float>(i - 1, j) > result.at<float>(i, j - 1)) {
    result.at<float>(i, j) = result.at<float>(i, j - 1);
    }
    else {
    	result.at<float>(i, j) = result.at<float>(i - 1, j);
    }
}
if ((i != 0 && j != 0) && image.at<uchar>(i - 1, j) > 0 && image.at<uchar>(i, j - 1) == 0) {
    result.at<float>(i, j) = result.at<float>(i - 1, j);
}
if ((i != 0 && j != 0) && image.at<uchar>(i - 1, j) == 0 && image.at<uchar>(i, j - 1) > 0) {
    result.at<float>(i, j) = result.at<float>(i, j - 1);
}
if ((i != 0 && j != 0) && image.at<uchar>(i - 1, j) == 0 && image.at<uchar>(i, j - 1) == 0) {
    label_count++;
    result.at<float>(i, j) = label_count;
    eq_table[label_count + 1] = label_count;
}