I am trying to write the code for component labeling which will label an array with randoms 1's and it will use a look up table and the 8-neigh. to label each one here some code but I am having a hard time with all the errors
Code:
#include "stdafx.h"//use in vc++ beta
#include <iostream>
#include <time.h>
#include <stack>
#include <string>
using namespace std;
//int r,c;
template <class LabelImage> // [r][c]>
class Stack;
//typedef stack<int> LabelImage
{
{
public: class LabelImage;
/** Creates a new instance of LabelImage */
int[][] label;
stack stack;
public LabelImage() {};
public int[][] labelImage(int[][] img, int stackSize) {
int nrow = img.length ;
int ncol = img[0].length ;
int lab = 1 ;
int [] pos ;
stack = new Stack( stackSize ) ;
label = new int[nrow][ncol] ;
for (int r = 1; r < nrow-1; r++)
for (int c = 1; c < ncol-1; c++) {
if (img[r][c] == 0) continue ;
if (label[r][c] > 0) continue ;
/* encountered unlabeled foreground pixel at position r, c */
/* push the position on the stack and assign label */
stack.push(new int [] {r, c}) ;
label[r][c] = lab ;
/* start the float fill */
while ( !stack.isEmpty()) {
pos = stack.pop() ;
int i = pos[0]; int j = pos[1];
if (img[i-1][j-1] == 1 && label[i-1][j-1] == 0) {
stack.push( new int[] {i-1,j-1} );
label[i-1][j-1] = lab ;
}
if (img[i-1][j] == 1 && label[i-1][j] == 0) {
stack.push( new int[] {i-1,j} );
label[i-1][j] = lab ;
}
if (img[i-1][j+1] == 1 && label[i-1][j+1] == 0) {
stack.push( new int[] {i-1,j+1} );
label[i-1][j+1] = lab ;
}
if (img[i][j-1] == 1 && label[i][j-1] == 0) {
stack.push( new int[] {i,j-1} );
label[i][j-1] = lab ;
}
if (img[i][j+1] == 1 && label[i][j+1] == 0) {
stack.push( new int[] {i,j+1} );
label[i][j+1] = lab ;
}
if (img[i+1][j-1] == 1 && label[i+1][j-1] == 0) {
stack.push( new int[] {i+1,j-1} );
label[i+1][j-1] = lab ;
}
if (img[i+1][j] == 1 && label[i+1][j] == 0) {
stack.push( new int[] {i+1,j} );
label[i+1][j] = lab ;
}
if (img[i+1][j+1] == 1 && label[i+1][j+1] == 0) {
stack.push( new int[] {i+1,j+1} );
label[i+1][j+1] = lab ;
}
} /* end while */
lab++ ;
}
return label ;
}
}
cout << "this is labelImage " << LabelImage << " ";
};
int main()
{
int x;
int y;
int arrayA[8][8]; // Declares an array like a chessboard source file
int arrayB[8][8]; //this is our output file shows which locations have ones
const int LOW = 1;
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
for ( x = 0; x < 8; x++ ) {
for ( y = 0; y < 8; y++ )
arrayA[x][y] = rand()% (LOW+1); // Set each element to a value
}
cout<<"Array Indices:\n";
for ( x = 0; x < 8; x++ ) {
for ( y = 0; y < 8; y++ )
cout<<"["<<x<<"]["<<y<<"]="<< arrayA[x][y] <<" ";
cout<<"\n";
}
cin.get();
cout << "\n";
return 0;
}