/* Diffuse water fill calibration implementation
Copy from:http://blog.csdn.net/zhjx2314/article/details/1629702
*/
Write good denoising, want to optimize the code, the results of noise that part of the lost ... You can rewrite it when you are free.
FloodFill (Mat &src) { structseed{intx; inty; }; classmpoint{ Public: Mpoint (intXxintYyintMflag) {x=xx; Y=yy; Flag=Mflag; } Public: intx; inty; intFlag; }; intRow =src.rows; intCol =Src.cols; intFlag = -; Seed*Seeds; intStackpoint; intPixe; //Current pixel position intCurX, Cury; //Allocate seed spaceSeeds =Newseed[row*Col]; //calculate the number of pixels per calibration value intcount[251]; for(inti =0; I <252; i++) {Count[i]=0;//initialized to 0} Uchar*p =Src.data; for(inti =0; i < src.rows; i++) { for(intj =0; J < Src.cols; J + +) { if(* (p + i*src.cols + j) = =0) {seeds[1].x =J; seeds[1].Y =i; Stackpoint=1; while(Stackpoint! =0) {CurX=seeds[stackpoint].x; Cury=seeds[stackpoint].y; Stackpoint--; //the pixel value in which the current pointer is locatedPixe = * (p + cury*col +CurX); //calibrate the pixel at the pointer* (p + cury*col + CurX) =Flag; Count[flag]++; //determine the point to the left, and if it is black, press the stack//precautions against cross-border if(CurX >0) {Pixe= * (p + cury*col + CurX-1); if(Pixe = =0) {Stackpoint++; seeds[stackpoint].x= CurX-1; Seeds[stackpoint].y=Cury; } } //determine the point to the right, and if it is black, press the stack//precautions against cross-border if(CurX <Col) {Pixe= * (p + cury*col + CurX +1); if(Pixe = =0) {Stackpoint++; seeds[stackpoint].x= CurX +1; Seeds[stackpoint].y=Cury; } } //determine the above point, if it is black, press the stack//precautions against cross-border if(Cury >0) {Pixe= * (p + (Cury-1) *col +CurX); if(Pixe = =0) {Stackpoint++; seeds[stackpoint].x=CurX; Seeds[stackpoint].y= Cury-1; } } //determine the point below, and if it is black, press the stack//precautions against cross-border if(Cury <Row) {Pixe= * (p + (Cury +1) *col +CurX); if(Pixe = =0) {Stackpoint++; seeds[stackpoint].x=CurX; Seeds[stackpoint].y= Cury +1; } } }//End while (stackpoint! = 0)Flag= (flag +7) %251;//changing the calibration value }//End If}//End for (i}//End for (J//Release Stackdelete Seeds;}
Connected Domain denoising