Click here to Skip to main content
15,887,979 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a project that read an image and then i segmented the image by watershed algorithm using emgu cv library...then i want to save it.
this is my code
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);}


but i had this exception :(

A generic error occurred in GDI+.
what should i do ?
Posted
Comments
Dave Kreskowiak 6-Jul-14 16:56pm    
On what line did the exception occur?
Esraa Saady 6-Jul-14 18:02pm    
on last line "boundaryImage.Tobitmap().save(apppath)
[no name] 6-Jul-14 20:56pm    
You might try supplying a filename instead of the name of a directory.

1 solution

OK, break that line down into two separate lines so you can see which method is throwing, ToBitmap or Save.

Chances are it's going to be the ToBitmap call. That's usually because the data isn't valid to build a bitmap with.

Get a hold of the people you got that library from and ask them what's going on.
 
Share this answer
 
Comments
Esraa Saady 6-Jul-14 20:44pm    
i break it..the error was for "save" not "toBitmap()"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900