Пример #1
0
void ArrayTest::get_minmax_bounds( int i, int /*j*/, int type, Scalar& low, Scalar& high )
{
    double l, u;
    int depth = CV_MAT_DEPTH(type);

    if( i == MASK )
    {
        l = -2;
        u = 2;
    }
    else if( depth < CV_32S )
    {
        l = getMinVal(type);
        u = getMaxVal(type);
    }
    else
    {
        u = depth == CV_32S ? 1000000 : 1000.;
        l = -u;
    }

    low = Scalar::all(l);
    high = Scalar::all(u);
}
Пример #2
0
void CCAnalyzer::labelCC()
{
	// Declaration
	point p;
	vector<point> neighbours;
	vector<int> L;

	// linked = []
	vector<int> linked;

	int nextLabel = 1;
    int currLabel;

	Rank->Add(0);	
	Parent->Add(-1); // dummy

	// First pass //
   
	//for column in row:
	for(int col=0; col<this->ysize; col++){
		// for row in data:
		for(int row=0; row<this->xsize; row++){
			// if data[row][col] is not Background
			if(!BArray[row][col]){
               // neighbours = connected elements with the current element's label
               // search the eight neighbors
				neighbours.clear();
				L.clear();

				if(row-1>=0 && !BArray[row-1][col]){
					p.x = row-1;
					p.y = col;
					neighbours.push_back(p);
					L.push_back(LabelArray[row-1][col]);
				}
				if(row-1>=0 && col-1>=0 && !BArray[row-1][col-1]){
					p.x = row-1;
					p.y = col-1;
					neighbours.push_back(p);
					L.push_back(LabelArray[row-1][col-1]);
				}
				if(col-1>=0 && !BArray[row][col-1]){
					p.x = row;
					p.y = col-1;
					neighbours.push_back(p);
					L.push_back(LabelArray[row][col-1]);
				}		
				if(row+1<xsize && col-1>=0 &&!BArray[row+1][col-1]){
					p.x = row+1;
					p.y = col-1;
					neighbours.push_back(p);
					L.push_back(LabelArray[row+1][col-1]);
				}

                //if neighbours is empty
				if(neighbours.size() == 0){
					//linked[NextLabel] = set containing NextLabel
					linked.push_back(nextLabel);
					
					// labels[row][column] = nextLabel
					Parent->Add(nextLabel);
					Rank->Add(0);
					LabelArray[row][col] = nextLabel;
					
					// NextLabel += 1
					nextLabel++;               
				}else{                   
                   // Find the smallest label
                   // L = neighbours labels - Already containing the labels
                   LabelArray[row][col] = getMinVal(L);
                   currLabel = LabelArray[row][col];

				   /*for label in L
                       linked[label] = union(linked[label], L)*/
 		
				   for(int labelNum=0; labelNum < L.size(); labelNum++){
					   if(currLabel != L[labelNum]){
							Union(currLabel, L[labelNum]);
					   }
				   }

				} // if(neighbours.size() == 0){
			} // if(BArray[row][col] != 0){
		} // for(int row=1;
	} // for(int col=1; 

	// End of First pass //

	// Second pass

	//for column in row:
	for(int col=0; col<this->ysize; col++){
		// for row in data:
		for(int row=0; row<this->xsize; row++){
			// if labels[row][column] is not Background
			if(LabelArray[row][col] != 0){
				// labels[row][col] = Find(labels[row][col])     
				LabelArray[row][col] = Find(LabelArray[row][col]);	
			}
		}
	}

	// End of Second pass //
	numberOflabels = renumber_labels(1) - 1;

	/*
	System::IO::StreamWriter^ sr = gcnew System::IO::StreamWriter("C:\\renum.txt");
	int currLab;
	for (int i = 0; i < xsize; i++)
	{
		for (int j = 0; j < ysize; j++)
		{
			currLab = LabelArray[i][j];
			if (currLab>0)
				sr->Write(" "+currLab);
			else
				sr->Write(" "+0);
		}
		sr->WriteLine();
	}
	sr->Close();
	*/
}