예제 #1
0
        /// <summary>
        /// Creates a new image that will be used as a mask for the histogram calculation.
        /// All forground points will be colored blue and all background points will be colored red.
        /// </summary>
        public static CVImage PrepareMask(CVImage image, Point[] forgroundPoints, Point[] backgroundPoints, bool includeNeautral, int floodFillThreshold)
        {
            CVImage outputImage = image.Clone();

            outputImage.Zero();

            FloodFillParams ffp = new FloodFillParams();

            ffp.Frame     = image;
            ffp.Threshold = floodFillThreshold;

            // fill all forground points in FG_COLOR
            foreach (Point pt in forgroundPoints)
            {
                RegionGrowing.Fill(pt, outputImage, new RegionGrowingCriteria(FloodFill), ffp, new LabelingFunc(RegionGrowing.DefaultLabeling), FG_COLOR);
            }

            // fill all background points in BG_COLOR
            foreach (Point pt in backgroundPoints)
            {
                RegionGrowing.Fill(pt, outputImage, new RegionGrowingCriteria(FloodFill), ffp, new LabelingFunc(RegionGrowing.DefaultLabeling), TEMP_BG_COLOR);
            }

            // now colorize to actual colors.
            for (int row = 0; row < outputImage.Height; ++row)
            {
                for (int col = 0; col < outputImage.Width; ++col)
                {
                    int argb = outputImage[row, col].ToColor().ToArgb();

                    if (includeNeautral)
                    {
                        if (argb == Color.Black.ToArgb())
                        {
                            outputImage[row, col] = new CVRgbPixel(NEAUTRAL_COLOR);
                        }
                    }

                    if (argb == TEMP_BG_COLOR.ToArgb())
                    {
                        outputImage[row, col] = new CVRgbPixel(BG_COLOR);
                    }
                }
            }

            // return as a grayscale image.
            CVImage grayscale = outputImage.ToGrayscale();

            outputImage.Release();
            return(grayscale);
        }
예제 #2
0
        /// <summary>
        /// This function applies the mask to image in the following way:
        ///  - All pixels in 'mask' that are blue are copied to the output image in maximum intensity.
        ///  - All pixels in 'mask' that are black are copied to the output image in half intensity.
        ///  - All pixels in 'mask' that are red are not copied at all to output image.
        /// </summary>
        public static CVImage ApplyMask(CVImage image, CVImage mask)
        {
            CVImage outputImage = image.Clone();

            outputImage.Zero();

            for (int row = 0; row < image.Height; ++row)
            {
                for (int col = 0; col < image.Width; ++col)
                {
                    // copy everything that's not background.
                    if (mask[row, col].ToColor().ToArgb() != Color.Black.ToArgb())
                    {
                        outputImage[row, col] = image[row, col];
                    }
                    else
                    {
                        outputImage[row, col] = new CVRgbPixel(TEMP_BG_COLOR);
                    }
                }
            }

            return(outputImage);
        }
예제 #3
0
파일: Path.cs 프로젝트: tdck/opencvdotnet
 private void ResetSegmentation()
 {
     segmentationImage = image.Clone();
     segPoints         = new List <Point>();
 }