void Readimage (OpenFileDialog openFileDialog) { //Read input image var image = new Image<Bgr, Byte>(openFileDialog.FileName); //Get the binary image Image<Gray, Byte> binary = image.Convert<Gray, Byte>().ThresholdBinaryInv(new Gray(140), new Gray(255)); var closeElement = new StructuringElementEx(5, 5, 2, 2,Emgu.CV.CvEnum.CV_ELEMENT_SHAPE.CV_SHAPE_ELLIPSE); binary = binary.MorphologyEx(closeElement, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_CLOSE, 1); //Eliminate noise and smaller objects Image<Gray, Byte> foreground = binary.Erode(6); //Identify image pixels without objects Image<Gray, Byte> background = binary.Dilate(6); background._ThresholdBinaryInv(new Gray(1), new Gray(128)); //Create markers image Image<Gray, Byte> markers = background + foreground; //Create watershed segmentation object WatershedSegmenter watershedSegmenter = new WatershedSegmenter(); //Set markers and process watershedSegmenter.SetMakers(markers); Image<Gray, Int32> boundaryImage = watershedSegmenter.Process(image); string appPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\ProImages\"; boundaryImage.ToBitmap().Save(appPath);}
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)