Exemplo n.º 1
0
        //
        private static void LargeEdgeMethodVariant(Bitmap img, Edgevariant variant, EdgeMethod method, EdgeDirection direction, double threshold)
        {
            string imgExtension = GetImageInfo.Imginfo(Imageinfo.Extension);
            string imgName      = GetImageInfo.Imginfo(Imageinfo.FileName);
            string defPath      = GetImageInfo.MyPath("Segmentation\\Edge");

            Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb);

            int[,] result = new int[img.Height, img.Width];
            string outName = String.Empty;
            double Depth   = System.Drawing.Image.GetPixelFormatSize(img.PixelFormat);

            double scale = 0; // for calculating the automatic threshold

            var imArray = MoreHelpers.BlackandWhiteProcessHelper(img);

            if (direction == EdgeDirection.def)
            {
                direction = EdgeDirection.both;
            }

            if ((imArray.GetLength(0) > 1 && imArray.GetLength(1) > 1) && (threshold >= 0 && threshold <= 1) && !(Checks.BinaryInput(img) && threshold == 0))
            {
                switch (method)
                {
                case EdgeMethod.Sobel:
                    scale = 4;     // for calculating the automatic threshold

                    if (variant == Edgevariant.var1)
                    {
                        result = EdgeHelperv1(scale, imArray, threshold, ImageFilter.Dx3FWindow("Sobel"), ImageFilter.Dx3FWindow("SobelT"), 8,
                                              direction, imgName, imgExtension, EdgeTempName._EdgeSobelVar1_temp);
                        if (threshold == 0 && direction == EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgeSobV1" + imgExtension;
                        }

                        else if (threshold == 0 && direction != EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgeSobV1_" + direction.ToString() + imgExtension;
                        }

                        else if (threshold != 0 && direction == EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgeSobV1" + "Th_" + threshold.ToString() + imgExtension;
                        }

                        else
                        {
                            outName = defPath + imgName + "_EdgeSobV1" + "Th_" + threshold.ToString() + "_" + direction.ToString() + imgExtension;
                        }
                    }
                    else
                    {
                        result = EdgeHelperv2(scale, imArray, threshold, ImageFilter.Dx3FWindow("Sobel"), ImageFilter.Dx3FWindow("SobelT"), 8, direction);
                        if (threshold == 0 && direction == EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgeSobV2" + imgExtension;
                        }

                        else if (threshold == 0 && direction != EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgeSobV2_" + direction.ToString() + imgExtension;
                        }

                        else if (threshold != 0 && direction == EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgeSobV2" + "Th_" + threshold.ToString() + imgExtension;
                        }

                        else
                        {
                            outName = defPath + imgName + "_EdgeSobV2" + "Th_" + threshold.ToString() + "_" + direction.ToString() + imgExtension;
                        }
                    }
                    break;

                case EdgeMethod.Prewitt:
                    scale = 4;     // for calculating the automatic threshold

                    if (variant == Edgevariant.var1)
                    {
                        result = EdgeHelperv1(scale, imArray, threshold, ImageFilter.Dx3FWindow("Prewitt"), ImageFilter.Dx3FWindow("PrewittT"), 8,
                                              direction, imgName, imgExtension, EdgeTempName._EdgePrewittVar1_temp);
                        if (threshold == 0 && direction == EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgePrewV1" + imgExtension;
                        }

                        else if (threshold == 0 && direction != EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgePrewV1_" + direction.ToString() + imgExtension;
                        }

                        else if (threshold != 0 && direction == EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgePrewV1" + "Th_" + threshold.ToString() + imgExtension;
                        }

                        else
                        {
                            outName = defPath + imgName + "_EdgePrewV1" + "Th_" + threshold.ToString() + "_" + direction.ToString() + imgExtension;
                        }
                    }
                    else
                    {
                        result = EdgeHelperv2(scale, imArray, threshold, ImageFilter.Dx3FWindow("Prewitt"), ImageFilter.Dx3FWindow("PrewittT"), 8, direction);
                        if (threshold == 0 && direction == EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgePrewV2" + imgExtension;
                        }

                        else if (threshold == 0 && direction != EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgePrewV2_" + direction.ToString() + imgExtension;
                        }

                        else if (threshold != 0 && direction == EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgePrewV2" + "Th_" + threshold.ToString() + imgExtension;
                        }

                        else
                        {
                            outName = defPath + imgName + "_EdgePrewV2" + "Th_" + threshold.ToString() + "_" + direction.ToString() + imgExtension;
                        }
                    }
                    break;

                case EdgeMethod.Roberts:
                    scale = 6;

                    if (variant == Edgevariant.var1)
                    {
                        result = EdgeHelperv1(scale, imArray, threshold, ImageFilter.Dx3FWindow("Roberts"), ImageFilter.Dx3FWindow("RobertsT"), 2,
                                              direction, imgName, imgExtension, EdgeTempName._EdgeRobertsVar1_temp);
                        if (threshold == 0 && direction == EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgeRobV1" + imgExtension;
                        }

                        else if (threshold == 0 && direction != EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgeRobV1_" + direction.ToString() + imgExtension;
                        }

                        else if (threshold != 0 && direction == EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgeRobV1" + "Th_" + threshold.ToString() + imgExtension;
                        }

                        else
                        {
                            outName = defPath + imgName + "_EdgeRobV1" + "Th_" + threshold.ToString() + "_" + direction.ToString() + imgExtension;
                        }
                    }
                    else
                    {
                        result = EdgeHelperv2(scale, imArray, threshold, ImageFilter.Dx3FWindow("Roberts"), ImageFilter.Dx3FWindow("RobertsT"), 2, direction);
                        if (threshold == 0 && direction == EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgeRobV2" + imgExtension;
                        }

                        else if (threshold == 0 && direction != EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgeRobV2_" + direction.ToString() + imgExtension;
                        }

                        else if (threshold != 0 && direction == EdgeDirection.def)
                        {
                            outName = defPath + imgName + "_EdgeRobV2" + "Th_" + threshold.ToString() + imgExtension;
                        }

                        else
                        {
                            outName = defPath + imgName + "_EdgeRobV2" + "Th_" + threshold.ToString() + "_" + direction.ToString() + imgExtension;
                        }
                    }
                    break;
                }

                image = Helpers.SetPixels(image, result, result, result);

                if (Depth == 8)
                {
                    PixelFormatWorks.Bpp24Gray2Gray8bppBitMap(image);
                }

                Helpers.SaveOptions(image, outName, imgExtension);
            }
            else
            {
                Console.WriteLine("Also Threshold must be in range [0..1]." +
                                  "\nOr may be Binary image at input and threshold = 0 - can`t process with such condition.");
            }
        }