I am trying to implement the Sequential Labeling Algorithm, which looks at a binary image and assigns a label to each image.
Code:int rows = im -> getNRows(); int cols = im -> getNCols(); char labels[rows][cols]; // fill labels array for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) labels[i][j] = '*' for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++){ int current_pixel = im -> getPixel(i,j); // 1 = white, 0 = black // A == white pixel && D has label (was scanned) -> A gets same label as D if ((current_pixel == 1) && (labels[i-1][j-1] != '*')) labels[i][j] = labels[i-1][j-1]; // A == white pixel && B has label (was scanned) -> A gets same label as B if ((current_pixel == 1) && (labels[i][j-1] != '*')) labels[i][j] = labels[i][j-1]; // A == white pixel && C has label (was scanned) -> A gets same label as C if ((current_pixel == 1) && (labels[i-1][j] != '*')) labels[i][j] = labels[i-1][j]; // B or C have no labels (bec new shape encountered) -> A gets new label if ((labels[i][j-1] == '*') || (labels[i-1][j] == '*')) labels[i][j] = 'a'; // B and C have different labels -> A gets either label if (labels[i][j-1] != labels[i-1][j]) labels[i][j] = labels[i][j-1]; } // print array into text file for (int i = 0; i < rows; i++){ for (int j = 0; j < cols; j++) cout << labels[i][j]; cout << endl; }
The problem is that print out does not represent the binary image, instead I get a row of * folowed by row of a folowed by a row of * folowed by a row of a ...
More on the Algorithm:
http://books.google.com/books?id=jpX...2oNxcbaYhIfAyw
pg. 69 - 71