예제 #1
0
        public SegmentationSolution SegmentImage(Image2D <Color> image, ObjectBackgroundColorModels colorModels)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            if (colorModels == null)
            {
                throw new ArgumentNullException("colorModels");
            }

            this.ImageSegmentator = new ImageSegmentator(
                image,
                colorModels,
                this.ColorDifferencePairwiseTermCutoff,
                this.ColorDifferencePairwiseTermWeight,
                this.ConstantPairwiseTermWeight,
                this.ObjectColorUnaryTermWeight,
                this.BackgroundColorUnaryTermWeight,
                this.ObjectShapeUnaryTermWeight,
                this.BackgroundShapeUnaryTermWeight);

            DebugConfiguration.WriteImportantDebugText(
                "Segmented image size is {0}x{1}.",
                this.ImageSegmentator.ImageSize.Width,
                this.ImageSegmentator.ImageSize.Height);

            SegmentationSolution solution = null;

            try
            {
                if (this.ShapeModel == null)
                {
                    throw new InvalidOperationException("Shape model must be specified before segmenting image.");
                }

                DebugConfiguration.WriteImportantDebugText("Running segmentation algorithm...");
                this.IsRunning = true;
                solution       = this.SegmentCurrentImage();

                if (solution == null)
                {
                    throw new InvalidOperationException("Segmentation solution can not be null.");
                }
            }
            finally
            {
                if (this.IsStopping)
                {
                    this.WasStopped = true;
                }

                this.IsRunning  = false;
                this.IsStopping = false;
            }

            DebugConfiguration.WriteImportantDebugText("Finished");

            return(solution);
        }
        public SegmentationSolution SegmentImage(Image2D<Color> image, ObjectBackgroundColorModels colorModels)
        {
            if (image == null)
                throw new ArgumentNullException("image");
            if (colorModels == null)
                throw new ArgumentNullException("colorModels");

            this.ImageSegmentator = new ImageSegmentator(
                image,
                colorModels,
                this.ColorDifferencePairwiseTermCutoff,
                this.ColorDifferencePairwiseTermWeight,
                this.ConstantPairwiseTermWeight,
                this.ObjectColorUnaryTermWeight,
                this.BackgroundColorUnaryTermWeight,
                this.ObjectShapeUnaryTermWeight,
                this.BackgroundShapeUnaryTermWeight);

            DebugConfiguration.WriteImportantDebugText(
                "Segmented image size is {0}x{1}.",
                this.ImageSegmentator.ImageSize.Width,
                this.ImageSegmentator.ImageSize.Height);

            SegmentationSolution solution = null;
            try
            {
                if (this.ShapeModel == null)
                    throw new InvalidOperationException("Shape model must be specified before segmenting image.");

                DebugConfiguration.WriteImportantDebugText("Running segmentation algorithm...");
                this.IsRunning = true;
                solution = this.SegmentCurrentImage();

                if (solution == null)
                    throw new InvalidOperationException("Segmentation solution can not be null.");
            }
            finally
            {
                if (this.IsStopping)
                    this.WasStopped = true;
                
                this.IsRunning = false;
                this.IsStopping = false;
            }

            DebugConfiguration.WriteImportantDebugText("Finished");

            return solution;
        }