Connected Domain denoising

Source: Internet
Author: User

/* 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.